diff --git a/Cargo.lock b/Cargo.lock index c3501a0f..ca879d05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -715,6 +715,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408" +dependencies = [ + "winapi", +] + [[package]] name = "http" version = "0.2.8" @@ -1910,6 +1919,7 @@ dependencies = [ "directories", "futures", "glob", + "home", "lazy_static", "log", "nix 0.24.2", diff --git a/Cargo.toml b/Cargo.toml index 749b80cb..15389834 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/topgrade-rs/topgrade" version = "10.0.0" authors = ["Roey Darwish Dror ", "Thomas Schönauer "] exclude = ["doc/screenshot.gif"] -edition = "2018" +edition = "2021" readme = "README.md" @@ -17,6 +17,7 @@ name = "topgrade" path = "src/main.rs" [dependencies] +home = "0.5" directories = "4.0" serde = { version = "1.0", features = ["derive"] } toml = "0.5" diff --git a/src/main.rs b/src/main.rs index cdcfe9e2..04e6eeb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,7 +140,7 @@ fn run() -> Result<()> { #[cfg(target_os = "linux")] let distribution = linux::Distribution::detect(); - #[cfg(target_os = "linux")] + #[cfg(target_os = r#"linux"#)] { match &distribution { Ok(distribution) => { diff --git a/src/steps/containers.rs b/src/steps/containers.rs index 39f6b160..3ad4b53d 100644 --- a/src/steps/containers.rs +++ b/src/steps/containers.rs @@ -23,7 +23,7 @@ fn list_containers(crt: &Path) -> Result> { crt.display() ); let output = Command::new(crt) - .args(&["image", "ls", "--format", "{{.Repository}}:{{.Tag}}"]) + .args(["image", "ls", "--format", "{{.Repository}}:{{.Tag}}"]) .output()?; let output_str = String::from_utf8(output.stdout)?; @@ -95,7 +95,7 @@ pub fn run_containers(ctx: &ExecutionContext) -> Result<()> { if ctx.config().cleanup() { // Remove dangling images debug!("Removing dangling images"); - if let Err(e) = ctx.run_type().execute(&crt).args(&["image", "prune", "-f"]).check_run() { + if let Err(e) = ctx.run_type().execute(&crt).args(["image", "prune", "-f"]).check_run() { error!("Removing dangling images failed: {}", e); success = false; } diff --git a/src/steps/emacs.rs b/src/steps/emacs.rs index 75ab817b..672fe3a2 100644 --- a/src/steps/emacs.rs +++ b/src/steps/emacs.rs @@ -71,7 +71,7 @@ impl Emacs { command.arg("--force"); } - command.args(&["upgrade"]); + command.args(["upgrade"]); command.check_run() } @@ -90,7 +90,7 @@ impl Emacs { let mut command = ctx.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 9f7dae43..b7eeda7c 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -52,7 +52,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() } @@ -65,7 +65,7 @@ pub fn run_flutter_upgrade(run_type: RunType) -> Result<()> { pub fn run_go(run_type: RunType) -> Result<()> { let go = utils::require("go")?; - let go_output = run_type.execute(&go).args(&["env", "GOPATH"]).check_output()?; + let go_output = run_type.execute(&go).args(["env", "GOPATH"]).check_output()?; let gopath = go_output.trim(); let go_global_update = utils::require("go-global-update") @@ -123,7 +123,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<()> { @@ -131,7 +131,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<()> { @@ -139,7 +139,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") { @@ -160,7 +160,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<()> { @@ -169,7 +169,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() @@ -181,8 +181,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<()> { @@ -190,7 +190,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<()> { @@ -200,7 +200,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() } @@ -209,7 +209,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<()> { @@ -239,7 +239,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<()> { @@ -253,7 +253,7 @@ pub fn run_conda_update(ctx: &ExecutionContext) -> Result<()> { let conda = utils::require("conda")?; let output = Command::new("conda") - .args(&["config", "--show", "auto_activate_base"]) + .args(["config", "--show", "auto_activate_base"]) .output()?; let string_output = String::from_utf8(output.stdout)?; debug!("Conda output: {}", string_output); @@ -265,14 +265,14 @@ pub fn run_conda_update(ctx: &ExecutionContext) -> Result<()> { ctx.run_type() .execute(&conda) - .args(&["update", "--all", "-y"]) + .args(["update", "--all", "-y"]) .check_run() } pub fn run_pip3_update(run_type: RunType) -> Result<()> { let python3 = utils::require("python3")?; Command::new(&python3) - .args(&["-m", "pip"]) + .args(["-m", "pip"]) .check_output() .map_err(|_| SkipStep("pip does not exists".to_string()))?; @@ -284,7 +284,7 @@ pub fn run_pip3_update(run_type: RunType) -> Result<()> { run_type .execute(&python3) - .args(&["-m", "pip", "install", "--upgrade", "--user", "pip"]) + .args(["-m", "pip", "install", "--upgrade", "--user", "pip"]) .check_run() } @@ -335,7 +335,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() } @@ -377,7 +377,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()))? @@ -415,7 +415,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()); @@ -436,7 +436,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()); @@ -459,7 +459,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()?; } @@ -471,7 +471,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<()> { @@ -490,7 +490,7 @@ pub fn spicetify_upgrade(ctx: &ExecutionContext) -> Result<()> { pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> { let gh = utils::require("gh")?; - let result = Command::new(&gh).args(&["extensions", "list"]).check_output(); + let result = Command::new(&gh).args(["extensions", "list"]).check_output(); if result.is_err() { debug!("GH result {:?}", result); return Err(SkipStep(String::from("GH failed")).into()); @@ -499,7 +499,7 @@ pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> { print_separator("GitHub CLI Extensions"); ctx.run_type() .execute(&gh) - .args(&["extension", "upgrade", "--all"]) + .args(["extension", "upgrade", "--all"]) .check_run() } @@ -510,6 +510,6 @@ pub fn update_julia_packages(ctx: &ExecutionContext) -> Result<()> { ctx.run_type() .execute(&julia) - .args(&["-e", "using Pkg; Pkg.update()"]) + .args(["-e", "using Pkg; Pkg.update()"]) .check_run() } diff --git a/src/steps/git.rs b/src/steps/git.rs index 32796f7a..859208f8 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() @@ -78,10 +78,10 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) - (Some(before), Some(after)) if before != after => { println!("{} {}:", style("Changed").yellow().bold(), &repo); - Command::new(&git) + 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| { @@ -162,10 +162,10 @@ impl Git { }; if let Some(git) = &self.git { - let output = Command::new(&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()); @@ -231,7 +231,8 @@ impl Git { let results = basic_rt.block_on(async { stream_of_futures.collect::>>().await }); let error = results.into_iter().find(|r| r.is_err()); - error.unwrap_or(Ok(())) + error.unwrap()?; + Ok(()) } } diff --git a/src/steps/kakoune.rs b/src/steps/kakoune.rs index d2fd4609..e06e2fe4 100644 --- a/src/steps/kakoune.rs +++ b/src/steps/kakoune.rs @@ -14,7 +14,7 @@ pub fn upgrade_kak_plug(ctx: &ExecutionContext) -> Result<()> { print_separator("Kakoune"); let mut command = ctx.run_type().execute(&kak); - command.args(&["-ui", "dummy", "-e", UPGRADE_KAK]); + command.args(["-ui", "dummy", "-e", UPGRADE_KAK]); let output = command.output()?; diff --git a/src/steps/node.rs b/src/steps/node.rs index 6d22d07e..ea1fbe4c 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -43,7 +43,7 @@ impl NPM { fn version(&self) -> Result { let version_str = Command::new(&self.command) - .args(&["--version"]) + .args(["--version"]) .check_output() .map(|s| s.trim().to_owned()); Version::parse(&version_str?).map_err(|err| err.into()) diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 96a35452..16051d20 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -125,7 +125,7 @@ impl Distribution { fn update_bedrock(ctx: &ExecutionContext) -> Result<()> { let sudo = require_option(ctx.sudo().as_ref(), String::from("Sudo required"))?; - ctx.run_type().execute(sudo).args(&["brl", "update"]); + ctx.run_type().execute(sudo).args(["brl", "update"]); let output = Command::new("brl").arg("list").output()?; debug!("brl list: {:?} {:?}", output.stdout, output.stderr); @@ -171,7 +171,7 @@ fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> { }; if let Some(sudo) = &ctx.sudo() { - let mut command = ctx.run_type().execute(&sudo); + let mut command = ctx.run_type().execute(sudo); command .arg(which("dnf").unwrap_or_else(|| Path::new("yum").to_path_buf())) .arg(if ctx.config().redhat_distro_sync() { @@ -198,7 +198,7 @@ fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> { fn upgrade_bedrock_strata(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - ctx.run_type().execute(&sudo).args(&["brl", "update"]).check_run()?; + ctx.run_type().execute(sudo).args(["brl", "update"]).check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); } @@ -208,11 +208,11 @@ fn upgrade_bedrock_strata(ctx: &ExecutionContext) -> Result<()> { fn upgrade_suse(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - ctx.run_type().execute(&sudo).args(&["zypper", "refresh"]).check_run()?; + ctx.run_type().execute(sudo).args(["zypper", "refresh"]).check_run()?; ctx.run_type() - .execute(&sudo) - .args(&["zypper", "dist-upgrade"]) + .execute(sudo) + .args(["zypper", "dist-upgrade"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -223,9 +223,9 @@ fn upgrade_suse(ctx: &ExecutionContext) -> Result<()> { fn upgrade_openmandriva(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { - let mut command = ctx.run_type().execute(&sudo); + let mut command = ctx.run_type().execute(sudo); - command.arg(which("dnf").unwrap().to_path_buf()).arg("upgrade"); + command.arg(&which("dnf").unwrap()).arg("upgrade"); if let Some(args) = ctx.config().dnf_arguments() { command.args(args.split_whitespace()); @@ -245,15 +245,15 @@ fn upgrade_openmandriva(ctx: &ExecutionContext) -> Result<()> { fn upgrade_void(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - let mut command = ctx.run_type().execute(&sudo); - command.args(&["xbps-install", "-Su", "xbps"]); + let mut command = ctx.run_type().execute(sudo); + command.args(["xbps-install", "-Su", "xbps"]); if ctx.config().yes(Step::System) { command.arg("-y"); } command.check_run()?; - let mut command = ctx.run_type().execute(&sudo); - command.args(&["xbps-install", "-u"]); + let mut command = ctx.run_type().execute(sudo); + command.args(["xbps-install", "-u"]); if ctx.config().yes(Step::System) { command.arg("-y"); } @@ -270,13 +270,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(&["emerge", "--sync"]) + .execute(sudo) + .args(["emerge", "--sync"]) .args( ctx.config() .emerge_sync_flags() @@ -286,11 +286,11 @@ fn upgrade_gentoo(ctx: &ExecutionContext) -> Result<()> { .check_run()?; if let Some(eix_update) = which("eix-update") { - run_type.execute(&sudo).arg(eix_update).check_run()?; + run_type.execute(sudo).arg(eix_update).check_run()?; } run_type - .execute(&sudo) + .execute(sudo) .arg("emerge") .args( ctx.config() @@ -314,10 +314,10 @@ fn upgrade_debian(ctx: &ExecutionContext) -> Result<()> { let is_nala = apt.ends_with("nala"); if !is_nala { - ctx.run_type().execute(&sudo).arg(&apt).arg("update").check_run()?; + ctx.run_type().execute(sudo).arg(&apt).arg("update").check_run()?; } - let mut command = ctx.run_type().execute(&sudo); + let mut command = ctx.run_type().execute(sudo); command.arg(&apt); if is_nala { command.arg("upgrade"); @@ -333,9 +333,9 @@ fn upgrade_debian(ctx: &ExecutionContext) -> Result<()> { command.check_run()?; if ctx.config().cleanup() { - ctx.run_type().execute(&sudo).arg(&apt).arg("clean").check_run()?; + ctx.run_type().execute(sudo).arg(&apt).arg("clean").check_run()?; - let mut command = ctx.run_type().execute(&sudo); + let mut command = ctx.run_type().execute(sudo); command.arg(&apt).arg("autoremove"); if ctx.config().yes(Step::System) { command.arg("-y"); @@ -366,7 +366,7 @@ pub fn run_deb_get(ctx: &ExecutionContext) -> Result<()> { fn upgrade_solus(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - ctx.run_type().execute(&sudo).args(&["eopkg", "upgrade"]).check_run()?; + ctx.run_type().execute(sudo).args(["eopkg", "upgrade"]).check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); } @@ -396,7 +396,7 @@ pub fn run_pacstall(ctx: &ExecutionContext) -> Result<()> { fn upgrade_clearlinux(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { - ctx.run_type().execute(&sudo).args(&["swupd", "update"]).check_run()?; + ctx.run_type().execute(sudo).args(["swupd", "update"]).check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); } @@ -406,28 +406,25 @@ fn upgrade_clearlinux(ctx: &ExecutionContext) -> Result<()> { fn upgrade_exherbo(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - ctx.run_type().execute(&sudo).args(&["cave", "sync"]).check_run()?; + ctx.run_type().execute(sudo).args(["cave", "sync"]).check_run()?; ctx.run_type() - .execute(&sudo) - .args(&["cave", "resolve", "world", "-c1", "-Cs", "-km", "-Km", "-x"]) + .execute(sudo) + .args(["cave", "resolve", "world", "-c1", "-Cs", "-km", "-Km", "-x"]) .check_run()?; if ctx.config().cleanup() { - ctx.run_type() - .execute(&sudo) - .args(&["cave", "purge", "-x"]) - .check_run()?; + ctx.run_type().execute(sudo).args(["cave", "purge", "-x"]).check_run()?; } ctx.run_type() - .execute(&sudo) - .args(&["cave", "fix-linkage", "-x", "--", "-Cs"]) + .execute(sudo) + .args(["cave", "fix-linkage", "-x", "--", "-Cs"]) .check_run()?; ctx.run_type() - .execute(&sudo) - .args(&["eclectic", "config", "interactive"]) + .execute(sudo) + .args(["eclectic", "config", "interactive"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -439,14 +436,14 @@ fn upgrade_exherbo(ctx: &ExecutionContext) -> Result<()> { 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"]) + .execute(sudo) + .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"]) + .execute(sudo) + .args(["/run/current-system/sw/bin/nix-collect-garbage", "-d"]) .check_run()?; } } else { @@ -465,8 +462,8 @@ fn upgrade_neon(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { let pkcon = which("pkcon").unwrap(); // pkcon ignores update with update and refresh provided together - ctx.run_type().execute(&sudo).arg(&pkcon).arg("refresh").check_run()?; - let mut exe = ctx.run_type().execute(&sudo); + ctx.run_type().execute(sudo).arg(&pkcon).arg("refresh").check_run()?; + let mut exe = ctx.run_type().execute(sudo); let cmd = exe.arg(&pkcon).arg("update"); if ctx.config().yes(Step::System) { cmd.arg("-y"); @@ -492,7 +489,7 @@ pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> print_separator("Check for needed restarts"); - run_type.execute(&sudo).arg(needrestart).check_run()?; + run_type.execute(sudo).arg(needrestart).check_run()?; Ok(()) } @@ -552,7 +549,7 @@ pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> { if yes { update_args.push("-y"); } - run_type.execute(&sudo).arg(&flatpak).args(&update_args).check_run()?; + run_type.execute(sudo).arg(&flatpak).args(&update_args).check_run()?; if cleanup { let mut cleanup_args = vec!["uninstall", "--system", "--unused"]; if yes { diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 4075d0fd..836e75a3 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -8,6 +8,7 @@ use crate::utils::{require, PathExt}; use crate::Step; use anyhow::Result; use directories::BaseDirs; +use home; use ini::Ini; use log::debug; use std::fs; @@ -90,16 +91,16 @@ pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { let version_str = run_type .execute(&fish) - .args(&["-c", "fisher --version"]) + .args(["-c", "fisher --version"]) .check_output()?; debug!("Fisher version: {}", version_str); if version_str.starts_with("fisher version 3.") { // v3 - see https://github.com/topgrade-rs/topgrade/pull/37#issuecomment-1283844506 - run_type.execute(&fish).args(&["-c", "fisher"]).check_run() + run_type.execute(&fish).args(["-c", "fisher"]).check_run() } else { // v4 - run_type.execute(&fish).args(&["-c", "fisher update"]).check_run() + run_type.execute(&fish).args(["-c", "fisher update"]).check_run() } } @@ -110,7 +111,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() } @@ -123,7 +124,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<()> { @@ -153,7 +154,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() } #[cfg(not(any(target_os = "android", target_os = "macos")))] @@ -164,7 +165,7 @@ pub fn upgrade_gnome_extensions(ctx: &ExecutionContext) -> Result<()> { "Desktop doest not appear to be gnome".to_string(), )?; let output = Command::new("gdbus") - .args(&[ + .args([ "call", "--session", "--dest", @@ -185,7 +186,7 @@ pub fn upgrade_gnome_extensions(ctx: &ExecutionContext) -> Result<()> { ctx.run_type() .execute(gdbus) - .args(&[ + .args([ "call", "--session", "--dest", @@ -215,7 +216,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() { @@ -280,7 +281,7 @@ pub fn run_guix(ctx: &ExecutionContext) -> Result<()> { print_separator("Guix"); if should_upgrade { - return run_type.execute(&guix).args(&["package", "-u"]).check_run(); + return run_type.execute(&guix).args(["package", "-u"]).check_run(); } Err(SkipStep(String::from("Guix Pull Failed, Skipping")).into()) } @@ -289,14 +290,14 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> { let nix = require("nix")?; let nix_channel = require("nix-channel")?; let nix_env = require("nix-env")?; - let profile_path = match env::home_dir() { + let profile_path = match home::home_dir() { Some(home) => Path::new(&home).join(".nix-profile"), None => Path::new("/nix/var/nix/profiles/per-user/default").into(), }; debug!("nix profile: {:?}", profile_path); let manifest_json_path = profile_path.join("manifest.json"); - let output = Command::new(&nix_env).args(&["--query", "nix"]).check_output(); + let output = Command::new(&nix_env).args(["--query", "nix"]).check_output(); debug!("nix-env output: {:?}", output); let should_self_upgrade = output.is_ok(); @@ -367,7 +368,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<()> { @@ -421,30 +422,27 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path); run_type .execute(&bash) - .args(&["-c", cmd_selfupdate.as_str()]) + .args(["-c", cmd_selfupdate.as_str()]) .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.as_str()]).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.as_str()]).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()]) + .args(["-c", cmd_flush_archives.as_str()]) .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()]) + .args(["-c", cmd_flush_temp.as_str()]) .check_run()?; } diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index fcb0acb4..78145ed1 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -26,7 +26,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()) @@ -78,8 +78,8 @@ impl Powershell { println!("Updating modules..."); ctx.run_type() - .execute(&powershell) - .args(&["-NoProfile", "-Command", &cmd.join(" ")]) + .execute(powershell) + .args(["-NoProfile", "-Command", &cmd.join(" ")]) .check_run() } diff --git a/src/steps/remote/ssh.rs b/src/steps/remote/ssh.rs index c759259a..5d498521 100644 --- a/src/steps/remote/ssh.rs +++ b/src/steps/remote/ssh.rs @@ -18,7 +18,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().run_in_tmux() && !ctx.run_type().dry() { #[cfg(unix)] @@ -42,7 +42,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]); print_separator(format!("Remote ({})", hostname)); println!("Connecting to {}...", hostname); diff --git a/src/steps/remote/vagrant.rs b/src/steps/remote/vagrant.rs index 1a248b26..712a2be9 100644 --- a/src/steps/remote/vagrant.rs +++ b/src/steps/remote/vagrant.rs @@ -113,7 +113,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 { @@ -140,7 +140,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(); @@ -198,7 +198,7 @@ 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() } @@ -207,7 +207,7 @@ pub fn upgrade_vagrant_boxes(ctx: &ExecutionContext) -> Result<()> { print_separator("Vagrant boxes"); let outdated = Command::new(&vagrant) - .args(&["box", "outdated", "--global"]) + .args(["box", "outdated", "--global"]) .check_output()?; let re = Regex::new(r"\* '(.*?)' for '(.*?)' is outdated").unwrap(); @@ -218,8 +218,8 @@ pub fn upgrade_vagrant_boxes(ctx: &ExecutionContext) -> Result<()> { let _ = ctx .run_type() .execute(&vagrant) - .args(&["box", "update", "--box"]) - .arg(&ele.get(1).unwrap().as_str()) + .args(["box", "update", "--box"]) + .arg(ele.get(1).unwrap().as_str()) .arg("--provider") .arg(ele.get(2).unwrap().as_str()) .check_run(); @@ -228,7 +228,7 @@ pub fn upgrade_vagrant_boxes(ctx: &ExecutionContext) -> Result<()> { if !found { println!("No outdated boxes") } else { - ctx.run_type().execute(&vagrant).args(&["box", "prune"]).check_run()?; + ctx.run_type().execute(&vagrant).args(["box", "prune"]).check_run()?; } Ok(()) 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/toolbx.rs b/src/steps/toolbx.rs index c4eafe17..e94c7bfe 100644 --- a/src/steps/toolbx.rs +++ b/src/steps/toolbx.rs @@ -8,7 +8,7 @@ use std::path::Path; use std::{path::PathBuf, process::Command}; fn list_toolboxes(toolbx: &Path) -> Result> { - let output = Command::new(toolbx).args(&["list", "--containers"]).output()?; + let output = Command::new(toolbx).args(["list", "--containers"]).output()?; let output_str = String::from_utf8(output.stdout)?; let proc: Vec = output_str diff --git a/src/steps/vim.rs b/src/steps/vim.rs index ecf0be87..d10f069d 100644 --- a/src/steps/vim.rs +++ b/src/steps/vim.rs @@ -45,12 +45,12 @@ fn upgrade(vim: &Path, vimrc: &Path, ctx: &ExecutionContext) -> Result<()> { tempfile.write_all(UPGRADE_VIM.replace('\r', "").as_bytes())?; debug!("Wrote vim script to {:?}", tempfile.path()); - let mut command = ctx.run_type().execute(&vim); + let mut command = ctx.run_type().execute(vim); command - .args(&["-u"]) + .args(["-u"]) .arg(vimrc) - .args(&["-U", "NONE", "-V1", "-nNesS"]) + .args(["-U", "NONE", "-V1", "-nNesS"]) .arg(tempfile.path()); if ctx.config().force_vim_plug_update() { @@ -88,17 +88,17 @@ pub fn upgrade_ultimate_vimrc(ctx: &ExecutionContext) -> Result<()> { ctx.run_type() .execute(&git) .current_dir(&config_dir) - .args(&["reset", "--hard"]) + .args(["reset", "--hard"]) .check_run()?; ctx.run_type() .execute(&git) .current_dir(&config_dir) - .args(&["clean", "-d", "--force"]) + .args(["clean", "-d", "--force"]) .check_run()?; ctx.run_type() .execute(&git) .current_dir(&config_dir) - .args(&["pull", "--rebase"]) + .args(["pull", "--rebase"]) .check_run()?; ctx.run_type() .execute(python) diff --git a/src/steps/zsh.rs b/src/steps/zsh.rs index 25a5e25d..9787c259 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.as_str()]).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.as_str()]).check_run() } pub fn run_zgenom(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { @@ -62,7 +62,7 @@ pub fn run_zgenom(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { print_separator("zgenom"); let cmd = format!("source {} && zgenom selfupdate && zgenom update", zshrc.display()); - run_type.execute(zsh).args(&["-l", "-c", cmd.as_str()]).check_run() + run_type.execute(zsh).args(["-l", "-c", cmd.as_str()]).check_run() } pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { @@ -76,7 +76,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<()> { @@ -91,7 +91,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.as_str()]).check_run() } pub fn run_zi(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { @@ -111,7 +111,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) @@ -122,7 +122,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() } @@ -135,7 +135,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 f63ff518..b6537fc8 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -104,7 +104,7 @@ impl Terminal { command.arg("-t"); command.arg(format!("{}", timeout.as_millis())); } - command.args(&["-a", "Topgrade", "Topgrade"]); + command.args(["-a", "Topgrade", "Topgrade"]); command.arg(message.as_ref()); command.output().ok(); }