diff --git a/src/config.rs b/src/config.rs index ac8775a1..aa0dbd0c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -286,7 +286,7 @@ 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; @@ -294,7 +294,7 @@ impl ConfigFile { } 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; diff --git a/src/main.rs b/src/main.rs index 2f6d7cba..65d99eeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(), + Ok(Key::Char('r' | 'R')) => reboot(), + Ok(Key::Char('q' | 'Q')) => (), + _ => continue, } break; } diff --git a/src/report.rs b/src/report.rs index a8efbea9..f8cd4855 100644 --- a/src/report.rs +++ b/src/report.rs @@ -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) } } diff --git a/src/steps/emacs.rs b/src/steps/emacs.rs index 9e941c9e..c4639be2 100644 --- a/src/steps/emacs.rs +++ b/src/steps/emacs.rs @@ -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<()> { @@ -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"); diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 74748ca4..9e7c75ca 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -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() } @@ -82,7 +82,7 @@ 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<()> { @@ -90,7 +90,7 @@ pub fn run_fossil(run_type: RunType) -> Result<()> { 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<()> { @@ -98,7 +98,7 @@ pub fn run_micro(run_type: RunType) -> Result<()> { print_separator("micro"); - let stdout = run_type.execute(µ).args(&["-plugin", "update"]).string_output()?; + let stdout = run_type.execute(µ).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") { @@ -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<()> { @@ -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() @@ -140,8 +140,8 @@ 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<()> { @@ -149,7 +149,7 @@ pub fn run_krew_upgrade(run_type: RunType) -> Result<()> { 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<()> { @@ -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() } @@ -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<()> { @@ -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<()> { @@ -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() } @@ -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() } @@ -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()))? @@ -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()); @@ -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()); @@ -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()?; } @@ -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<()> { diff --git a/src/steps/git.rs b/src/steps/git.rs index 32796f7a..5fde7a89 100644 --- a/src/steps/git.rs +++ b/src/steps/git.rs @@ -53,7 +53,7 @@ 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()); @@ -61,7 +61,7 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) - 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() @@ -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", @@ -107,7 +107,7 @@ fn get_head_revision(git: &Path, repo: &str) -> Option { 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| { @@ -122,7 +122,7 @@ fn has_remotes(git: &Path, repo: &str) -> Option { 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| { @@ -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()); diff --git a/src/steps/node.rs b/src/steps/node.rs index a4ac77a0..b6bb6e02 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -27,7 +27,7 @@ impl NPM { #[cfg(target_os = "linux")] fn root(&self) -> Result { Command::new(&self.command) - .args(&["root", "-g"]) + .args(["root", "-g"]) .check_output() .map(|s| PathBuf::from(s.trim())) } @@ -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(()) @@ -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<()> { diff --git a/src/steps/os/dragonfly.rs b/src/steps/os/dragonfly.rs index 79003263..1a8ade5f 100644 --- a/src/steps/os/dragonfly.rs +++ b/src/steps/os/dragonfly.rs @@ -10,7 +10,7 @@ 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() } @@ -18,7 +18,7 @@ pub fn audit_packages(sudo: &Option) -> 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()?; } diff --git a/src/steps/os/freebsd.rs b/src/steps/os/freebsd.rs index bdd6ba76..078600a7 100644 --- a/src/steps/os/freebsd.rs +++ b/src/steps/os/freebsd.rs @@ -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) -> Result<()> { if let Some(sudo) = sudo { println!(); Command::new(sudo) - .args(&["/usr/sbin/pkg", "audit", "-Fr"]) + .args(["/usr/sbin/pkg", "audit", "-Fr"]) .spawn()? .wait()?; } diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index f0c10da0..8a96e31d 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -48,12 +48,12 @@ impl Distribution { Ok(match id { Some("alpine") => Distribution::Alpine, - Some("centos") | Some("rhel") | Some("ol") => Distribution::CentOS, + Some("centos" | "rhel" | "ol") => Distribution::CentOS, Some("clear-linux-os") => Distribution::ClearLinux, Some("fedora") => Distribution::Fedora, Some("void") => Distribution::Void, Some("debian") => Distribution::Debian, - Some("arch") | Some("anarchy") | Some("manjaro-arm") | Some("garuda") | Some("artix") => Distribution::Arch, + Some("arch" | "anarchy" | "manjaro-arm" | "garuda" | "artix") => Distribution::Arch, Some("solus") => Distribution::Solus, Some("gentoo") => Distribution::Gentoo, Some("exherbo") => Distribution::Exherbo, @@ -291,12 +291,12 @@ fn upgrade_suse(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/zypper", "refresh"]) + .args(["/usr/bin/zypper", "refresh"]) .check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/zypper", "dist-upgrade"]) + .args(["/usr/bin/zypper", "dist-upgrade"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -309,12 +309,12 @@ fn upgrade_void(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/xbps-install", "-Su", "xbps"]) + .args(["/usr/bin/xbps-install", "-Su", "xbps"]) .check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/xbps-install", "-u"]) + .args(["/usr/bin/xbps-install", "-u"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -328,13 +328,13 @@ fn upgrade_gentoo(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { if let Some(layman) = which("layman") { - run_type.execute(&sudo).arg(layman).args(&["-s", "ALL"]).check_run()?; + run_type.execute(&sudo).arg(layman).args(["-s", "ALL"]).check_run()?; } println!("Syncing portage"); run_type .execute(&sudo) - .args(&["/usr/bin/emerge", "--sync"]) + .args(["/usr/bin/emerge", "--sync"]) .args( ctx.config() .emerge_sync_flags() @@ -400,7 +400,7 @@ fn upgrade_solus(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/eopkg", "upgrade"]) + .args(["/usr/bin/eopkg", "upgrade"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -413,7 +413,7 @@ fn upgrade_clearlinux(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/swupd", "update"]) + .args(["/usr/bin/swupd", "update"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -426,29 +426,29 @@ fn upgrade_exherbo(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/cave", "sync"]) + .args(["/usr/bin/cave", "sync"]) .check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/cave", "resolve", "world", "-c1", "-Cs", "-km", "-Km", "-x"]) + .args(["/usr/bin/cave", "resolve", "world", "-c1", "-Cs", "-km", "-Km", "-x"]) .check_run()?; if ctx.config().cleanup() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/cave", "purge", "-x"]) + .args(["/usr/bin/cave", "purge", "-x"]) .check_run()?; } ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/cave", "fix-linkage", "-x", "--", "-Cs"]) + .args(["/usr/bin/cave", "fix-linkage", "-x", "--", "-Cs"]) .check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/eclectic", "config", "interactive"]) + .args(["/usr/bin/eclectic", "config", "interactive"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -461,13 +461,13 @@ fn upgrade_nixos(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { ctx.run_type() .execute(&sudo) - .args(&["/run/current-system/sw/bin/nixos-rebuild", "switch", "--upgrade"]) + .args(["/run/current-system/sw/bin/nixos-rebuild", "switch", "--upgrade"]) .check_run()?; if ctx.config().cleanup() { ctx.run_type() .execute(&sudo) - .args(&["/run/current-system/sw/bin/nix-collect-garbage", "-d"]) + .args(["/run/current-system/sw/bin/nix-collect-garbage", "-d"]) .check_run()?; } } else { @@ -553,7 +553,7 @@ pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> { run_type .execute(&flatpak) - .args(&["update", "--user", "-y"]) + .args(["update", "--user", "-y"]) .check_run()?; print_separator("Flatpak System Packages"); @@ -561,12 +561,12 @@ pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> { run_type .execute(sudo) .arg(flatpak) - .args(&["update", "--system", "-y"]) + .args(["update", "--system", "-y"]) .check_run() } else { run_type .execute(&flatpak) - .args(&["update", "--system", "-y"]) + .args(["update", "--system", "-y"]) .check_run() } } diff --git a/src/steps/os/macos.rs b/src/steps/os/macos.rs index 3fb39a9f..2b1ea977 100644 --- a/src/steps/os/macos.rs +++ b/src/steps/os/macos.rs @@ -10,15 +10,15 @@ pub fn run_macports(ctx: &ExecutionContext) -> Result<()> { require("port")?; let sudo = ctx.sudo().as_ref().unwrap(); print_separator("MacPorts"); - ctx.run_type().execute(sudo).args(&["port", "selfupdate"]).check_run()?; + ctx.run_type().execute(sudo).args(["port", "selfupdate"]).check_run()?; ctx.run_type() .execute(sudo) - .args(&["port", "-u", "upgrade", "outdated"]) + .args(["port", "-u", "upgrade", "outdated"]) .check_run()?; if ctx.config().cleanup() { ctx.run_type() .execute(sudo) - .args(&["port", "-N", "reclaim"]) + .args(["port", "-N", "reclaim"]) .check_run()?; } @@ -58,7 +58,7 @@ pub fn upgrade_macos(ctx: &ExecutionContext) -> Result<()> { } let mut command = ctx.run_type().execute("softwareupdate"); - command.args(&["--install", "--all"]); + command.args(["--install", "--all"]); if should_ask { command.arg("--no-scan"); diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 0729dada..cc55bb79 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -74,7 +74,7 @@ pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { print_separator("Fisher"); - run_type.execute(&fish).args(&["-c", "fisher update"]).check_run() + run_type.execute(&fish).args(["-c", "fisher update"]).check_run() } pub fn run_bashit(ctx: &ExecutionContext) -> Result<()> { @@ -84,7 +84,7 @@ pub fn run_bashit(ctx: &ExecutionContext) -> Result<()> { ctx.run_type() .execute("bash") - .args(&["-lic", &format!("bash-it update {}", ctx.config().bashit_branch())]) + .args(["-lic", &format!("bash-it update {}", ctx.config().bashit_branch())]) .check_run() } @@ -97,7 +97,7 @@ pub fn run_oh_my_fish(ctx: &ExecutionContext) -> Result<()> { print_separator("oh-my-fish"); - ctx.run_type().execute(&fish).args(&["-c", "omf update"]).check_run() + ctx.run_type().execute(&fish).args(["-c", "omf update"]).check_run() } pub fn run_pkgin(ctx: &ExecutionContext) -> Result<()> { @@ -127,7 +127,7 @@ pub fn run_fish_plug(ctx: &ExecutionContext) -> Result<()> { print_separator("fish-plug"); - ctx.run_type().execute(&fish).args(&["-c", "plug update"]).check_run() + ctx.run_type().execute(&fish).args(["-c", "plug update"]).check_run() } pub fn run_brew_formula(ctx: &ExecutionContext, variant: BrewVariant) -> Result<()> { @@ -138,7 +138,7 @@ pub fn run_brew_formula(ctx: &ExecutionContext, variant: BrewVariant) -> Result< variant.execute(run_type).arg("update").check_run()?; variant .execute(run_type) - .args(&["upgrade", "--ignore-pinned", "--formula"]) + .args(["upgrade", "--ignore-pinned", "--formula"]) .check_run()?; if ctx.config().cleanup() { @@ -156,19 +156,19 @@ pub fn run_brew_cask(ctx: &ExecutionContext, variant: BrewVariant) -> Result<()> let cask_upgrade_exists = variant .execute(RunType::Wet) - .args(&["--repository", "buo/cask-upgrade"]) + .args(["--repository", "buo/cask-upgrade"]) .check_output() .map(|p| Path::new(p.trim()).exists())?; let mut brew_args = vec![]; if cask_upgrade_exists { - brew_args.extend(&["cu", "-y"]); + brew_args.extend(["cu", "-y"]); if ctx.config().brew_cask_greedy() { brew_args.push("-a"); } } else { - brew_args.extend(&["upgrade", "--cask"]); + brew_args.extend(["upgrade", "--cask"]); if ctx.config().brew_cask_greedy() { brew_args.push("--greedy"); } @@ -205,10 +205,7 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> { if multi_user { if let Some(sudo) = ctx.sudo() { - run_type - .execute(&sudo) - .args(&["-i", "nix", "upgrade-nix"]) - .check_run()?; + run_type.execute(&sudo).args(["-i", "nix", "upgrade-nix"]).check_run()?; } else { print_warning("Need sudo to upgrade Nix"); } @@ -238,7 +235,7 @@ pub fn run_asdf(run_type: RunType) -> Result<()> { return Err(TopgradeError::ProcessFailed(e).into()); } } - run_type.execute(&asdf).args(&["plugin", "update", "--all"]).check_run() + run_type.execute(&asdf).args(["plugin", "update", "--all"]).check_run() } pub fn run_home_manager(run_type: RunType) -> Result<()> { @@ -276,32 +273,20 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res print_separator("SDKMAN!"); let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path); - run_type - .execute(&bash) - .args(&["-c", cmd_selfupdate.as_str()]) - .check_run()?; + run_type.execute(&bash).args(["-c", &cmd_selfupdate]).check_run()?; let cmd_update = format!("source {} && sdk update", &sdkman_init_path); - run_type.execute(&bash).args(&["-c", cmd_update.as_str()]).check_run()?; + run_type.execute(&bash).args(["-c", &cmd_update]).check_run()?; let cmd_upgrade = format!("source {} && sdk upgrade", &sdkman_init_path); - run_type - .execute(&bash) - .args(&["-c", cmd_upgrade.as_str()]) - .check_run()?; + run_type.execute(&bash).args(["-c", &cmd_upgrade]).check_run()?; if cleanup { let cmd_flush_archives = format!("source {} && sdk flush archives", &sdkman_init_path); - run_type - .execute(&bash) - .args(&["-c", cmd_flush_archives.as_str()]) - .check_run()?; + run_type.execute(&bash).args(["-c", &cmd_flush_archives]).check_run()?; let cmd_flush_temp = format!("source {} && sdk flush temp", &sdkman_init_path); - run_type - .execute(&bash) - .args(&["-c", cmd_flush_temp.as_str()]) - .check_run()?; + run_type.execute(&bash).args(["-c", &cmd_flush_temp]).check_run()?; } Ok(()) diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index 850fa90e..d0cc5f29 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -40,7 +40,7 @@ pub fn run_winget(ctx: &ExecutionContext) -> Result<()> { print_separator("winget"); - ctx.run_type().execute(&winget).args(&["upgrade", "--all"]).check_run() + ctx.run_type().execute(&winget).args(["upgrade", "--all"]).check_run() } pub fn run_scoop(cleanup: bool, run_type: RunType) -> Result<()> { @@ -48,11 +48,11 @@ pub fn run_scoop(cleanup: bool, run_type: RunType) -> Result<()> { print_separator("Scoop"); - run_type.execute(&scoop).args(&["update"]).check_run()?; - run_type.execute(&scoop).args(&["update", "*"]).check_run()?; + run_type.execute(&scoop).args(["update"]).check_run()?; + run_type.execute(&scoop).args(["update", "*"]).check_run()?; if cleanup { - run_type.execute(&scoop).args(&["cleanup", "*"]).check_run()?; + run_type.execute(&scoop).args(["cleanup", "*"]).check_run()?; } Ok(()) @@ -61,13 +61,13 @@ pub fn run_scoop(cleanup: bool, run_type: RunType) -> Result<()> { pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> { let wsl = require("wsl")?; let topgrade = Command::new(&wsl) - .args(&["bash", "-lc", "which topgrade"]) + .args(["bash", "-lc", "which topgrade"]) .check_output() .map_err(|_| SkipStep(String::from("Could not find Topgrade installed in WSL")))?; let mut command = ctx.run_type().execute(&wsl); command - .args(&["bash", "-c"]) + .args(["bash", "-c"]) .arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade)); if ctx.config().yes() { @@ -94,7 +94,7 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> { } pub fn reboot() { - Command::new("shutdown").args(&["/R", "/T", "0"]).spawn().ok(); + Command::new("shutdown").args(["/R", "/T", "0"]).spawn().ok(); } pub fn insert_startup_scripts(ctx: &ExecutionContext, git_repos: &mut Repositories) -> Result<()> { diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index b5fa0fd2..08a3bbfd 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -23,7 +23,7 @@ impl Powershell { let profile = path.as_ref().and_then(|path| { Command::new(path) - .args(&["-NoProfile", "-Command", "Split-Path $profile"]) + .args(["-NoProfile", "-Command", "Split-Path $profile"]) .check_output() .map(|output| PathBuf::from(output.trim())) .and_then(|p| p.require()) @@ -44,7 +44,7 @@ impl Powershell { #[cfg(windows)] pub fn has_module(powershell: &Path, command: &str) -> bool { Command::new(&powershell) - .args(&[ + .args([ "-NoProfile", "-Command", &format!("Get-Module -ListAvailable {}", command), @@ -76,7 +76,7 @@ impl Powershell { println!("Updating modules..."); ctx.run_type() .execute(&powershell) - .args(&["-NoProfile", "-Command", &cmd.join(" ")]) + .args(["-NoProfile", "-Command", &cmd.join(" ")]) .check_run() } @@ -103,7 +103,7 @@ impl Powershell { }; command - .args(&[ + .args([ "-NoProfile", "-Command", &format!( diff --git a/src/steps/remote/ssh.rs b/src/steps/remote/ssh.rs index e8345f53..add1a625 100644 --- a/src/steps/remote/ssh.rs +++ b/src/steps/remote/ssh.rs @@ -17,7 +17,7 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> { } let env = format!("TOPGRADE_PREFIX={}", hostname); - args.extend(&["env", &env, "$SHELL", "-lc", topgrade]); + args.extend(["env", &env, "$SHELL", "-lc", topgrade]); if ctx.config().yes() { args.push("-y"); @@ -45,7 +45,7 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> { } let env = format!("TOPGRADE_PREFIX={}", hostname); - args.extend(&["env", &env, "$SHELL", "-lc", topgrade]); + args.extend(["env", &env, "$SHELL", "-lc", topgrade]); if ctx.config().yes() { args.push("-y"); diff --git a/src/steps/remote/vagrant.rs b/src/steps/remote/vagrant.rs index 3c4af976..736b69f0 100644 --- a/src/steps/remote/vagrant.rs +++ b/src/steps/remote/vagrant.rs @@ -110,7 +110,7 @@ impl<'a> TemporaryPowerOn<'a> { ctx.run_type() .execute(vagrant) - .args(&[subcommand, &vagrant_box.name]) + .args([subcommand, &vagrant_box.name]) .current_dir(vagrant_box.path.clone()) .check_run()?; Ok(TemporaryPowerOn { @@ -137,7 +137,7 @@ impl<'a> Drop for TemporaryPowerOn<'a> { self.ctx .run_type() .execute(self.vagrant) - .args(&[subcommand, &self.vagrant_box.name]) + .args([subcommand, &self.vagrant_box.name]) .current_dir(self.vagrant_box.path.clone()) .check_run() .ok(); @@ -195,6 +195,6 @@ pub fn topgrade_vagrant_box(ctx: &ExecutionContext, vagrant_box: &VagrantBox) -> ctx.run_type() .execute(&vagrant.path) .current_dir(&vagrant_box.path) - .args(&["ssh", "-c", &command]) + .args(["ssh", "-c", &command]) .check_run() } diff --git a/src/steps/tmux.rs b/src/steps/tmux.rs index 7fef1591..14a726d8 100644 --- a/src/steps/tmux.rs +++ b/src/steps/tmux.rs @@ -49,7 +49,7 @@ impl Tmux { fn has_session(&self, session_name: &str) -> Result { Ok(self .build() - .args(&["has-session", "-t", session_name]) + .args(["has-session", "-t", session_name]) .output()? .status .success()) @@ -58,7 +58,7 @@ impl Tmux { fn new_session(&self, session_name: &str) -> Result { Ok(self .build() - .args(&["new-session", "-d", "-s", session_name, "-n", "dummy"]) + .args(["new-session", "-d", "-s", session_name, "-n", "dummy"]) .spawn()? .wait()? .success()) @@ -66,7 +66,7 @@ impl Tmux { fn run_in_session(&self, command: &str) -> Result<()> { self.build() - .args(&["new-window", "-t", "topgrade", command]) + .args(["new-window", "-t", "topgrade", command]) .spawn()? .wait()? .check()?; @@ -94,12 +94,12 @@ pub fn run_in_tmux(args: &Option) -> ! { tmux.run_in_session(&command).expect("Error running topgrade in tmux"); tmux.build() - .args(&["kill-window", "-t", "topgrade:dummy"]) + .args(["kill-window", "-t", "topgrade:dummy"]) .output() .expect("Error killing the dummy tmux window"); if env::var("TMUX").is_err() { - let err = tmux.build().args(&["attach", "-t", "topgrade"]).exec(); + let err = tmux.build().args(["attach", "-t", "topgrade"]).exec(); panic!("{:?}", err); } else { println!("Topgrade launched in a new tmux session"); @@ -110,7 +110,7 @@ pub fn run_in_tmux(args: &Option) -> ! { pub fn run_command(ctx: &ExecutionContext, command: &str) -> Result<()> { Tmux::new(ctx.config().tmux_arguments()) .build() - .args(&["new-window", "-a", "-t", "topgrade:1", command]) + .args(["new-window", "-a", "-t", "topgrade:1", command]) .env_remove("TMUX") .spawn()? .wait()? diff --git a/src/steps/vim.rs b/src/steps/vim.rs index 43ff6834..aabda31a 100644 --- a/src/steps/vim.rs +++ b/src/steps/vim.rs @@ -48,9 +48,9 @@ fn upgrade(vim: &Path, vimrc: &Path, ctx: &ExecutionContext) -> Result<()> { let output = ctx .run_type() .execute(&vim) - .args(&["-u"]) + .arg("-u") .arg(vimrc) - .args(&["-U", "NONE", "-V1", "-nNesS"]) + .args(["-U", "NONE", "-V1", "-nNesS"]) .arg(tempfile.path()) .output()?; diff --git a/src/steps/zsh.rs b/src/steps/zsh.rs index e769d836..c2e6e53f 100644 --- a/src/steps/zsh.rs +++ b/src/steps/zsh.rs @@ -19,7 +19,7 @@ pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { print_separator("zr"); let cmd = format!("source {} && zr --update", zshrc(base_dirs).display()); - run_type.execute(zsh).args(&["-l", "-c", cmd.as_str()]).check_run() + run_type.execute(zsh).args(["-l", "-c", &cmd]).check_run() } pub fn zshrc(base_dirs: &BaseDirs) -> PathBuf { @@ -48,7 +48,7 @@ pub fn run_antigen(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { print_separator("antigen"); let cmd = format!("source {} && antigen selfupdate && antigen update", zshrc.display()); - run_type.execute(zsh).args(&["-l", "-c", cmd.as_str()]).check_run() + run_type.execute(zsh).args(["-l", "-c", &cmd]).check_run() } pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { @@ -62,7 +62,7 @@ pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { print_separator("zplug"); - run_type.execute(zsh).args(&["-i", "-c", "zplug update"]).check_run() + run_type.execute(zsh).args(["-i", "-c", "zplug update"]).check_run() } pub fn run_zinit(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { @@ -77,7 +77,7 @@ pub fn run_zinit(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { print_separator("zinit"); let cmd = format!("source {} && zinit self-update && zinit update --all", zshrc.display(),); - run_type.execute(zsh).args(&["-i", "-c", cmd.as_str()]).check_run() + run_type.execute(zsh).args(["-i", "-c", &cmd]).check_run() } pub fn run_zim(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { @@ -85,7 +85,7 @@ pub fn run_zim(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { env::var("ZIM_HOME") .or_else(|_| { Command::new("zsh") - .args(&["-c", "[[ -n ${ZIM_HOME} ]] && print -n ${ZIM_HOME}"]) + .args(["-c", "[[ -n ${ZIM_HOME} ]] && print -n ${ZIM_HOME}"]) .check_output() }) .map(PathBuf::from) @@ -96,7 +96,7 @@ pub fn run_zim(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { run_type .execute(zsh) - .args(&["-i", "-c", "zimfw upgrade && zimfw update"]) + .args(["-i", "-c", "zimfw upgrade && zimfw update"]) .check_run() } @@ -109,7 +109,7 @@ pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> { let custom_dir = env::var::<_>("ZSH_CUSTOM") .or_else(|_| { Command::new("zsh") - .args(&["-c", "test $ZSH_CUSTOM && echo -n $ZSH_CUSTOM"]) + .args(["-c", "test $ZSH_CUSTOM && echo -n $ZSH_CUSTOM"]) .check_output() }) .map(PathBuf::from) diff --git a/src/terminal.rs b/src/terminal.rs index c41eacd0..c8e2da1d 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -97,7 +97,7 @@ impl Terminal { if let Some(timeout) = timeout { command.arg("-t"); command.arg(format!("{}", timeout.as_millis())); - command.args(&["-a", "Topgrade"]); + command.args(["-a", "Topgrade"]); command.arg(message.as_ref()); } command.output().ok(); @@ -229,18 +229,18 @@ impl Terminal { let answer = loop { match self.term.read_key() { - Ok(Key::Char('y')) | Ok(Key::Char('Y')) => break Ok(true), - Ok(Key::Char('s')) | Ok(Key::Char('S')) => { + Ok(Key::Char('y' | 'Y')) => break Ok(true), + Ok(Key::Char('s' | 'S')) => { println!("\n\nDropping you to shell. Fix what you need and then exit the shell.\n"); run_shell(); break Ok(true); } - Ok(Key::Char('n')) | Ok(Key::Char('N')) | Ok(Key::Enter) => break Ok(false), + Ok(Key::Char('n' | 'N') | Key::Enter) => break Ok(false), Err(e) => { error!("Error reading from terminal: {}", e); break Ok(false); } - Ok(Key::Char('q')) | Ok(Key::Char('Q')) => return Err(io::Error::from(io::ErrorKind::Interrupted)), + Ok(Key::Char('q' | 'Q')) => return Err(io::Error::from(io::ErrorKind::Interrupted)), _ => (), } }; diff --git a/src/utils.rs b/src/utils.rs index 3ea1fb3f..9f8bb0b7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -136,9 +136,5 @@ pub fn require + Debug>(binary_name: T) -> Result { #[allow(dead_code)] pub fn require_option(option: Option, cause: String) -> Result { - if let Some(value) = option { - Ok(value) - } else { - Err(SkipStep(cause).into()) - } + option.ok_or_else(|| SkipStep(cause).into()) }