Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Add minor refactorings #754

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ impl ConfigFile {
})?;

if let Some(ref mut paths) = &mut result.git_repos {
for path in paths.iter_mut() {
for path in paths {
let expanded = shellexpand::tilde::<&str>(&path.as_ref()).into_owned();
debug!("Path {} expanded to {}", path, expanded);
*path = expanded;
}
}

if let Some(paths) = result.git.as_mut().and_then(|git| git.repos.as_mut()) {
for path in paths.iter_mut() {
for path in paths {
let expanded = shellexpand::tilde::<&str>(&path.as_ref()).into_owned();
debug!("Path {} expanded to {}", path, expanded);
*path = expanded;
Expand Down
14 changes: 4 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,10 @@ fn run() -> Result<()> {
print_info("\n(R)eboot\n(S)hell\n(Q)uit");
loop {
match get_key() {
Ok(Key::Char('s')) | Ok(Key::Char('S')) => {
run_shell();
}
Ok(Key::Char('r')) | Ok(Key::Char('R')) => {
reboot();
}
Ok(Key::Char('q')) | Ok(Key::Char('Q')) => (),
_ => {
continue;
}
Ok(Key::Char('s' | 'S')) => run_shell(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. Could you tell me which feature of Rust are you using here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested "or patterns", introduced in Rust 1.53

Ok(Key::Char('r' | 'R')) => reboot(),
Ok(Key::Char('q' | 'Q')) => (),
_ => continue,
}
break;
}
Expand Down
5 changes: 1 addition & 4 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ pub enum StepResult {

impl StepResult {
pub fn failed(&self) -> bool {
match self {
StepResult::Success | StepResult::Ignored | StepResult::Skipped(_) => false,
StepResult::Failure => true,
}
matches!(self, StepResult::Failure)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/steps/emacs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Emacs {
fn update_doom(doom: &Path, run_type: RunType) -> Result<()> {
print_separator("Doom Emacs");

run_type.execute(doom).args(&["-y", "upgrade"]).check_run()
run_type.execute(doom).args(["-y", "upgrade"]).check_run()
}

pub fn upgrade(&self, run_type: RunType) -> Result<()> {
Expand All @@ -76,7 +76,7 @@ impl Emacs {
let mut command = run_type.execute(&emacs);

command
.args(&["--batch", "--debug-init", "-l"])
.args(["--batch", "--debug-init", "-l"])
.arg(init_file)
.arg("--eval");

Expand Down
38 changes: 19 additions & 19 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn run_cargo_update(ctx: &ExecutionContext) -> Result<()> {

ctx.run_type()
.execute(cargo_update)
.args(&["install-update", "--git", "--all"])
.args(["install-update", "--git", "--all"])
.check_run()
}

Expand Down Expand Up @@ -82,23 +82,23 @@ pub fn run_sheldon(ctx: &ExecutionContext) -> Result<()> {

print_separator("Sheldon");

ctx.run_type().execute(&sheldon).args(&["lock", "--update"]).check_run()
ctx.run_type().execute(&sheldon).args(["lock", "--update"]).check_run()
}

pub fn run_fossil(run_type: RunType) -> Result<()> {
let fossil = utils::require("fossil")?;

print_separator("Fossil");

run_type.execute(&fossil).args(&["all", "sync"]).check_run()
run_type.execute(&fossil).args(["all", "sync"]).check_run()
}

pub fn run_micro(run_type: RunType) -> Result<()> {
let micro = utils::require("micro")?;

print_separator("micro");

let stdout = run_type.execute(&micro).args(&["-plugin", "update"]).string_output()?;
let stdout = run_type.execute(&micro).args(["-plugin", "update"]).string_output()?;
std::io::stdout().write_all(stdout.as_bytes())?;

if stdout.contains("Nothing to install / update") || stdout.contains("One or more plugins installed") {
Expand All @@ -119,7 +119,7 @@ pub fn run_apm(run_type: RunType) -> Result<()> {

print_separator("Atom Package Manager");

run_type.execute(&apm).args(&["upgrade", "--confirm=false"]).check_run()
run_type.execute(&apm).args(["upgrade", "--confirm=false"]).check_run()
}

pub fn run_rustup(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
Expand All @@ -128,7 +128,7 @@ pub fn run_rustup(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
print_separator("rustup");

if rustup.canonicalize()?.is_descendant_of(base_dirs.home_dir()) {
run_type.execute(&rustup).args(&["self", "update"]).check_run()?;
run_type.execute(&rustup).args(["self", "update"]).check_run()?;
}

run_type.execute(&rustup).arg("update").check_run()
Expand All @@ -140,16 +140,16 @@ pub fn run_choosenim(ctx: &ExecutionContext) -> Result<()> {
print_separator("choosenim");
let run_type = ctx.run_type();

run_type.execute(&choosenim).args(&["update", "self"]).check_run()?;
run_type.execute(&choosenim).args(&["update", "stable"]).check_run()
run_type.execute(&choosenim).args(["update", "self"]).check_run()?;
run_type.execute(&choosenim).args(["update", "stable"]).check_run()
}

pub fn run_krew_upgrade(run_type: RunType) -> Result<()> {
let krew = utils::require("kubectl-krew")?;

print_separator("Krew");

run_type.execute(&krew).args(&["upgrade"]).check_run()
run_type.execute(&krew).args(["upgrade"]).check_run()
}

pub fn run_gcloud_components_update(run_type: RunType) -> Result<()> {
Expand All @@ -159,7 +159,7 @@ pub fn run_gcloud_components_update(run_type: RunType) -> Result<()> {

run_type
.execute(&gcloud)
.args(&["components", "update", "--quiet"])
.args(["components", "update", "--quiet"])
.check_run()
}

Expand All @@ -168,7 +168,7 @@ pub fn run_jetpack(run_type: RunType) -> Result<()> {

print_separator("Jetpack");

run_type.execute(&jetpack).args(&["global", "update"]).check_run()
run_type.execute(&jetpack).args(["global", "update"]).check_run()
}

pub fn run_rtcl(ctx: &ExecutionContext) -> Result<()> {
Expand All @@ -192,7 +192,7 @@ pub fn run_vcpkg_update(run_type: RunType) -> Result<()> {
let vcpkg = utils::require("vcpkg")?;
print_separator("vcpkg");

run_type.execute(&vcpkg).args(&["upgrade", "--no-dry-run"]).check_run()
run_type.execute(&vcpkg).args(["upgrade", "--no-dry-run"]).check_run()
}

pub fn run_pipx_update(run_type: RunType) -> Result<()> {
Expand All @@ -212,7 +212,7 @@ pub fn run_pip3_update(run_type: RunType) -> Result<()> {

run_type
.execute(&pip3)
.args(&["install", "--upgrade", "--user", "pip"])
.args(["install", "--upgrade", "--user", "pip"])
.check_run()
}

Expand Down Expand Up @@ -263,7 +263,7 @@ pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> {
c.arg(&tlmgr);
c
};
command.args(&["update", "--self", "--all"]);
command.args(["update", "--self", "--all"]);

command.check_run()
}
Expand Down Expand Up @@ -305,7 +305,7 @@ pub fn run_custom_command(name: &str, command: &str, ctx: &ExecutionContext) ->
pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
let composer = utils::require("composer")?;
let composer_home = Command::new(&composer)
.args(&["global", "config", "--absolute", "--quiet", "home"])
.args(["global", "config", "--absolute", "--quiet", "home"])
.check_output()
.map_err(|e| (SkipStep(format!("Error getting the composer directory: {}", e))))
.map(|s| PathBuf::from(s.trim()))?
Expand Down Expand Up @@ -343,7 +343,7 @@ pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
}
}

let output = Command::new(&composer).args(&["global", "update"]).output()?;
let output = Command::new(&composer).args(["global", "update"]).output()?;
let status = output.status;
if !status.success() {
return Err(TopgradeError::ProcessFailed(status).into());
Expand All @@ -364,7 +364,7 @@ pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
let dotnet = utils::require("dotnet")?;

let output = Command::new(dotnet).args(&["tool", "list", "--global"]).output()?;
let output = Command::new(dotnet).args(["tool", "list", "--global"]).output()?;

if !output.status.success() {
return Err(SkipStep(format!("dotnet failed with exit code {:?}", output.status)).into());
Expand All @@ -387,7 +387,7 @@ pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
let package_name = package.split_whitespace().next().unwrap();
ctx.run_type()
.execute("dotnet")
.args(&["tool", "update", package_name, "--global"])
.args(["tool", "update", package_name, "--global"])
.check_run()?;
}

Expand All @@ -399,7 +399,7 @@ pub fn run_raco_update(run_type: RunType) -> Result<()> {

print_separator("Racket Package Manager");

run_type.execute(&raco).args(&["pkg", "update", "--all"]).check_run()
run_type.execute(&raco).args(["pkg", "update", "--all"]).check_run()
}

pub fn bin_update(ctx: &ExecutionContext) -> Result<()> {
Expand Down
12 changes: 6 additions & 6 deletions src/steps/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) -
command
.stdin(Stdio::null())
.current_dir(&repo)
.args(&["pull", "--ff-only"]);
.args(["pull", "--ff-only"]);

if let Some(extra_arguments) = ctx.config().git_arguments() {
command.args(extra_arguments.split_whitespace());
}

let pull_output = command.output().await?;
let submodule_output = AsyncCommand::new(git)
.args(&["submodule", "update", "--recursive"])
.args(["submodule", "update", "--recursive"])
.current_dir(&repo)
.stdin(Stdio::null())
.output()
Expand All @@ -81,7 +81,7 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) -
Command::new(&git)
.stdin(Stdio::null())
.current_dir(&repo)
.args(&[
.args([
"--no-pager",
"log",
"--no-decorate",
Expand All @@ -107,7 +107,7 @@ fn get_head_revision(git: &Path, repo: &str) -> Option<String> {
Command::new(git)
.stdin(Stdio::null())
.current_dir(repo)
.args(&["rev-parse", "HEAD"])
.args(["rev-parse", "HEAD"])
.check_output()
.map(|output| output.trim().to_string())
.map_err(|e| {
Expand All @@ -122,7 +122,7 @@ fn has_remotes(git: &Path, repo: &str) -> Option<bool> {
Command::new(git)
.stdin(Stdio::null())
.current_dir(repo)
.args(&["remote", "show"])
.args(["remote", "show"])
.check_output()
.map(|output| output.lines().count() > 0)
.map_err(|e| {
Expand Down Expand Up @@ -165,7 +165,7 @@ impl Git {
let output = Command::new(&git)
.stdin(Stdio::null())
.current_dir(path)
.args(&["rev-parse", "--show-toplevel"])
.args(["rev-parse", "--show-toplevel"])
.check_output()
.ok()
.map(|output| output.trim().to_string());
Expand Down
8 changes: 4 additions & 4 deletions src/steps/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl NPM {
#[cfg(target_os = "linux")]
fn root(&self) -> Result<PathBuf> {
Command::new(&self.command)
.args(&["root", "-g"])
.args(["root", "-g"])
.check_output()
.map(|s| PathBuf::from(s.trim()))
}
Expand All @@ -37,10 +37,10 @@ impl NPM {
run_type
.execute("sudo")
.arg(&self.command)
.args(&["update", "-g"])
.args(["update", "-g"])
.check_run()?;
} else {
run_type.execute(&self.command).args(&["update", "-g"]).check_run()?;
run_type.execute(&self.command).args(["update", "-g"]).check_run()?;
}

Ok(())
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn pnpm_global_update(run_type: RunType) -> Result<()> {
let pnpm = require("pnpm")?;

print_separator("Performant Node Package Manager");
run_type.execute(&pnpm).args(&["update", "-g"]).check_run()
run_type.execute(&pnpm).args(["update", "-g"]).check_run()
}

pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/steps/os/dragonfly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()>
print_separator("DrgaonFly BSD Packages");
run_type
.execute(sudo)
.args(&["/usr/local/sbin/pkg", "upgrade"])
.args(["/usr/local/sbin/pkg", "upgrade"])
.check_run()
}

pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<()> {
if let Some(sudo) = sudo {
println!();
Command::new(sudo)
.args(&["/usr/local/sbin/pkg", "audit", "-Fr"])
.args(["/usr/local/sbin/pkg", "audit", "-Fr"])
.spawn()?
.wait()?;
}
Expand Down
6 changes: 3 additions & 3 deletions src/steps/os/freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ pub fn upgrade_freebsd(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()>
print_separator("FreeBSD Update");
run_type
.execute(sudo)
.args(&["/usr/sbin/freebsd-update", "fetch", "install"])
.args(["/usr/sbin/freebsd-update", "fetch", "install"])
.check_run()
}

pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
let sudo = require_option(sudo, String::from("No sudo detected"))?;
print_separator("FreeBSD Packages");
run_type.execute(sudo).args(&["/usr/sbin/pkg", "upgrade"]).check_run()
run_type.execute(sudo).args(["/usr/sbin/pkg", "upgrade"]).check_run()
}

pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<()> {
if let Some(sudo) = sudo {
println!();
Command::new(sudo)
.args(&["/usr/sbin/pkg", "audit", "-Fr"])
.args(["/usr/sbin/pkg", "audit", "-Fr"])
.spawn()?
.wait()?;
}
Expand Down
Loading