Add minor refactorings (#754)

This commit is contained in:
Marcin Puc
2021-09-04 20:01:19 +02:00
committed by GitHub
parent 7db0c03621
commit 1478d079ca
21 changed files with 119 additions and 147 deletions

View File

@@ -286,7 +286,7 @@ impl ConfigFile {
})?; })?;
if let Some(ref mut paths) = &mut result.git_repos { 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(); let expanded = shellexpand::tilde::<&str>(&path.as_ref()).into_owned();
debug!("Path {} expanded to {}", path, expanded); debug!("Path {} expanded to {}", path, expanded);
*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()) { 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(); let expanded = shellexpand::tilde::<&str>(&path.as_ref()).into_owned();
debug!("Path {} expanded to {}", path, expanded); debug!("Path {} expanded to {}", path, expanded);
*path = expanded; *path = expanded;

View File

@@ -405,16 +405,10 @@ fn run() -> Result<()> {
print_info("\n(R)eboot\n(S)hell\n(Q)uit"); print_info("\n(R)eboot\n(S)hell\n(Q)uit");
loop { loop {
match get_key() { match get_key() {
Ok(Key::Char('s')) | Ok(Key::Char('S')) => { Ok(Key::Char('s' | 'S')) => run_shell(),
run_shell(); Ok(Key::Char('r' | 'R')) => reboot(),
} Ok(Key::Char('q' | 'Q')) => (),
Ok(Key::Char('r')) | Ok(Key::Char('R')) => { _ => continue,
reboot();
}
Ok(Key::Char('q')) | Ok(Key::Char('Q')) => (),
_ => {
continue;
}
} }
break; break;
} }

View File

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

View File

@@ -58,7 +58,7 @@ impl Emacs {
fn update_doom(doom: &Path, run_type: RunType) -> Result<()> { fn update_doom(doom: &Path, run_type: RunType) -> Result<()> {
print_separator("Doom Emacs"); 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<()> { pub fn upgrade(&self, run_type: RunType) -> Result<()> {
@@ -76,7 +76,7 @@ impl Emacs {
let mut command = run_type.execute(&emacs); let mut command = run_type.execute(&emacs);
command command
.args(&["--batch", "--debug-init", "-l"]) .args(["--batch", "--debug-init", "-l"])
.arg(init_file) .arg(init_file)
.arg("--eval"); .arg("--eval");

View File

@@ -49,7 +49,7 @@ pub fn run_cargo_update(ctx: &ExecutionContext) -> Result<()> {
ctx.run_type() ctx.run_type()
.execute(cargo_update) .execute(cargo_update)
.args(&["install-update", "--git", "--all"]) .args(["install-update", "--git", "--all"])
.check_run() .check_run()
} }
@@ -82,7 +82,7 @@ pub fn run_sheldon(ctx: &ExecutionContext) -> Result<()> {
print_separator("Sheldon"); 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<()> { pub fn run_fossil(run_type: RunType) -> Result<()> {
@@ -90,7 +90,7 @@ pub fn run_fossil(run_type: RunType) -> Result<()> {
print_separator("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<()> { pub fn run_micro(run_type: RunType) -> Result<()> {
@@ -98,7 +98,7 @@ pub fn run_micro(run_type: RunType) -> Result<()> {
print_separator("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())?; std::io::stdout().write_all(stdout.as_bytes())?;
if stdout.contains("Nothing to install / update") || stdout.contains("One or more plugins installed") { 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"); 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<()> { 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"); print_separator("rustup");
if rustup.canonicalize()?.is_descendant_of(base_dirs.home_dir()) { 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() run_type.execute(&rustup).arg("update").check_run()
@@ -140,8 +140,8 @@ pub fn run_choosenim(ctx: &ExecutionContext) -> Result<()> {
print_separator("choosenim"); print_separator("choosenim");
let run_type = ctx.run_type(); let run_type = ctx.run_type();
run_type.execute(&choosenim).args(&["update", "self"]).check_run()?; run_type.execute(&choosenim).args(["update", "self"]).check_run()?;
run_type.execute(&choosenim).args(&["update", "stable"]).check_run() run_type.execute(&choosenim).args(["update", "stable"]).check_run()
} }
pub fn run_krew_upgrade(run_type: RunType) -> Result<()> { 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"); 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<()> { 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 run_type
.execute(&gcloud) .execute(&gcloud)
.args(&["components", "update", "--quiet"]) .args(["components", "update", "--quiet"])
.check_run() .check_run()
} }
@@ -168,7 +168,7 @@ pub fn run_jetpack(run_type: RunType) -> Result<()> {
print_separator("Jetpack"); 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<()> { 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")?; let vcpkg = utils::require("vcpkg")?;
print_separator("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<()> { pub fn run_pipx_update(run_type: RunType) -> Result<()> {
@@ -212,7 +212,7 @@ pub fn run_pip3_update(run_type: RunType) -> Result<()> {
run_type run_type
.execute(&pip3) .execute(&pip3)
.args(&["install", "--upgrade", "--user", "pip"]) .args(["install", "--upgrade", "--user", "pip"])
.check_run() .check_run()
} }
@@ -263,7 +263,7 @@ pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> {
c.arg(&tlmgr); c.arg(&tlmgr);
c c
}; };
command.args(&["update", "--self", "--all"]); command.args(["update", "--self", "--all"]);
command.check_run() 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<()> { pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
let composer = utils::require("composer")?; let composer = utils::require("composer")?;
let composer_home = Command::new(&composer) let composer_home = Command::new(&composer)
.args(&["global", "config", "--absolute", "--quiet", "home"]) .args(["global", "config", "--absolute", "--quiet", "home"])
.check_output() .check_output()
.map_err(|e| (SkipStep(format!("Error getting the composer directory: {}", e)))) .map_err(|e| (SkipStep(format!("Error getting the composer directory: {}", e))))
.map(|s| PathBuf::from(s.trim()))? .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; let status = output.status;
if !status.success() { if !status.success() {
return Err(TopgradeError::ProcessFailed(status).into()); 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<()> { pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
let dotnet = utils::require("dotnet")?; 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() { if !output.status.success() {
return Err(SkipStep(format!("dotnet failed with exit code {:?}", output.status)).into()); 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(); let package_name = package.split_whitespace().next().unwrap();
ctx.run_type() ctx.run_type()
.execute("dotnet") .execute("dotnet")
.args(&["tool", "update", package_name, "--global"]) .args(["tool", "update", package_name, "--global"])
.check_run()?; .check_run()?;
} }
@@ -399,7 +399,7 @@ pub fn run_raco_update(run_type: RunType) -> Result<()> {
print_separator("Racket Package Manager"); 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<()> { pub fn bin_update(ctx: &ExecutionContext) -> Result<()> {

View File

@@ -53,7 +53,7 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) -
command command
.stdin(Stdio::null()) .stdin(Stdio::null())
.current_dir(&repo) .current_dir(&repo)
.args(&["pull", "--ff-only"]); .args(["pull", "--ff-only"]);
if let Some(extra_arguments) = ctx.config().git_arguments() { if let Some(extra_arguments) = ctx.config().git_arguments() {
command.args(extra_arguments.split_whitespace()); 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 pull_output = command.output().await?;
let submodule_output = AsyncCommand::new(git) let submodule_output = AsyncCommand::new(git)
.args(&["submodule", "update", "--recursive"]) .args(["submodule", "update", "--recursive"])
.current_dir(&repo) .current_dir(&repo)
.stdin(Stdio::null()) .stdin(Stdio::null())
.output() .output()
@@ -81,7 +81,7 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) -
Command::new(&git) Command::new(&git)
.stdin(Stdio::null()) .stdin(Stdio::null())
.current_dir(&repo) .current_dir(&repo)
.args(&[ .args([
"--no-pager", "--no-pager",
"log", "log",
"--no-decorate", "--no-decorate",
@@ -107,7 +107,7 @@ fn get_head_revision(git: &Path, repo: &str) -> Option<String> {
Command::new(git) Command::new(git)
.stdin(Stdio::null()) .stdin(Stdio::null())
.current_dir(repo) .current_dir(repo)
.args(&["rev-parse", "HEAD"]) .args(["rev-parse", "HEAD"])
.check_output() .check_output()
.map(|output| output.trim().to_string()) .map(|output| output.trim().to_string())
.map_err(|e| { .map_err(|e| {
@@ -122,7 +122,7 @@ fn has_remotes(git: &Path, repo: &str) -> Option<bool> {
Command::new(git) Command::new(git)
.stdin(Stdio::null()) .stdin(Stdio::null())
.current_dir(repo) .current_dir(repo)
.args(&["remote", "show"]) .args(["remote", "show"])
.check_output() .check_output()
.map(|output| output.lines().count() > 0) .map(|output| output.lines().count() > 0)
.map_err(|e| { .map_err(|e| {
@@ -165,7 +165,7 @@ impl Git {
let output = Command::new(&git) let output = Command::new(&git)
.stdin(Stdio::null()) .stdin(Stdio::null())
.current_dir(path) .current_dir(path)
.args(&["rev-parse", "--show-toplevel"]) .args(["rev-parse", "--show-toplevel"])
.check_output() .check_output()
.ok() .ok()
.map(|output| output.trim().to_string()); .map(|output| output.trim().to_string());

View File

@@ -27,7 +27,7 @@ impl NPM {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn root(&self) -> Result<PathBuf> { fn root(&self) -> Result<PathBuf> {
Command::new(&self.command) Command::new(&self.command)
.args(&["root", "-g"]) .args(["root", "-g"])
.check_output() .check_output()
.map(|s| PathBuf::from(s.trim())) .map(|s| PathBuf::from(s.trim()))
} }
@@ -37,10 +37,10 @@ impl NPM {
run_type run_type
.execute("sudo") .execute("sudo")
.arg(&self.command) .arg(&self.command)
.args(&["update", "-g"]) .args(["update", "-g"])
.check_run()?; .check_run()?;
} else { } else {
run_type.execute(&self.command).args(&["update", "-g"]).check_run()?; run_type.execute(&self.command).args(["update", "-g"]).check_run()?;
} }
Ok(()) Ok(())
@@ -84,7 +84,7 @@ pub fn pnpm_global_update(run_type: RunType) -> Result<()> {
let pnpm = require("pnpm")?; let pnpm = require("pnpm")?;
print_separator("Performant Node Package Manager"); 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<()> { pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> {

View File

@@ -10,7 +10,7 @@ pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()>
print_separator("DrgaonFly BSD Packages"); print_separator("DrgaonFly BSD Packages");
run_type run_type
.execute(sudo) .execute(sudo)
.args(&["/usr/local/sbin/pkg", "upgrade"]) .args(["/usr/local/sbin/pkg", "upgrade"])
.check_run() .check_run()
} }
@@ -18,7 +18,7 @@ pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<()> {
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
println!(); println!();
Command::new(sudo) Command::new(sudo)
.args(&["/usr/local/sbin/pkg", "audit", "-Fr"]) .args(["/usr/local/sbin/pkg", "audit", "-Fr"])
.spawn()? .spawn()?
.wait()?; .wait()?;
} }

View File

@@ -10,21 +10,21 @@ pub fn upgrade_freebsd(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()>
print_separator("FreeBSD Update"); print_separator("FreeBSD Update");
run_type run_type
.execute(sudo) .execute(sudo)
.args(&["/usr/sbin/freebsd-update", "fetch", "install"]) .args(["/usr/sbin/freebsd-update", "fetch", "install"])
.check_run() .check_run()
} }
pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> { pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
let sudo = require_option(sudo, String::from("No sudo detected"))?; let sudo = require_option(sudo, String::from("No sudo detected"))?;
print_separator("FreeBSD Packages"); 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<()> { pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<()> {
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
println!(); println!();
Command::new(sudo) Command::new(sudo)
.args(&["/usr/sbin/pkg", "audit", "-Fr"]) .args(["/usr/sbin/pkg", "audit", "-Fr"])
.spawn()? .spawn()?
.wait()?; .wait()?;
} }

View File

@@ -48,12 +48,12 @@ impl Distribution {
Ok(match id { Ok(match id {
Some("alpine") => Distribution::Alpine, 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("clear-linux-os") => Distribution::ClearLinux,
Some("fedora") => Distribution::Fedora, Some("fedora") => Distribution::Fedora,
Some("void") => Distribution::Void, Some("void") => Distribution::Void,
Some("debian") => Distribution::Debian, 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("solus") => Distribution::Solus,
Some("gentoo") => Distribution::Gentoo, Some("gentoo") => Distribution::Gentoo,
Some("exherbo") => Distribution::Exherbo, Some("exherbo") => Distribution::Exherbo,
@@ -291,12 +291,12 @@ fn upgrade_suse(ctx: &ExecutionContext) -> Result<()> {
if let Some(sudo) = ctx.sudo() { if let Some(sudo) = ctx.sudo() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/zypper", "refresh"]) .args(["/usr/bin/zypper", "refresh"])
.check_run()?; .check_run()?;
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/zypper", "dist-upgrade"]) .args(["/usr/bin/zypper", "dist-upgrade"])
.check_run()?; .check_run()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
@@ -309,12 +309,12 @@ fn upgrade_void(ctx: &ExecutionContext) -> Result<()> {
if let Some(sudo) = ctx.sudo() { if let Some(sudo) = ctx.sudo() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/xbps-install", "-Su", "xbps"]) .args(["/usr/bin/xbps-install", "-Su", "xbps"])
.check_run()?; .check_run()?;
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/xbps-install", "-u"]) .args(["/usr/bin/xbps-install", "-u"])
.check_run()?; .check_run()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); 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(sudo) = &ctx.sudo() {
if let Some(layman) = which("layman") { 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"); println!("Syncing portage");
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/emerge", "--sync"]) .args(["/usr/bin/emerge", "--sync"])
.args( .args(
ctx.config() ctx.config()
.emerge_sync_flags() .emerge_sync_flags()
@@ -400,7 +400,7 @@ fn upgrade_solus(ctx: &ExecutionContext) -> Result<()> {
if let Some(sudo) = ctx.sudo() { if let Some(sudo) = ctx.sudo() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/eopkg", "upgrade"]) .args(["/usr/bin/eopkg", "upgrade"])
.check_run()?; .check_run()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
@@ -413,7 +413,7 @@ fn upgrade_clearlinux(ctx: &ExecutionContext) -> Result<()> {
if let Some(sudo) = &ctx.sudo() { if let Some(sudo) = &ctx.sudo() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/swupd", "update"]) .args(["/usr/bin/swupd", "update"])
.check_run()?; .check_run()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
@@ -426,29 +426,29 @@ fn upgrade_exherbo(ctx: &ExecutionContext) -> Result<()> {
if let Some(sudo) = ctx.sudo() { if let Some(sudo) = ctx.sudo() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/cave", "sync"]) .args(["/usr/bin/cave", "sync"])
.check_run()?; .check_run()?;
ctx.run_type() ctx.run_type()
.execute(&sudo) .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()?; .check_run()?;
if ctx.config().cleanup() { if ctx.config().cleanup() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/cave", "purge", "-x"]) .args(["/usr/bin/cave", "purge", "-x"])
.check_run()?; .check_run()?;
} }
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/cave", "fix-linkage", "-x", "--", "-Cs"]) .args(["/usr/bin/cave", "fix-linkage", "-x", "--", "-Cs"])
.check_run()?; .check_run()?;
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/eclectic", "config", "interactive"]) .args(["/usr/bin/eclectic", "config", "interactive"])
.check_run()?; .check_run()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
@@ -461,13 +461,13 @@ fn upgrade_nixos(ctx: &ExecutionContext) -> Result<()> {
if let Some(sudo) = ctx.sudo() { if let Some(sudo) = ctx.sudo() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/run/current-system/sw/bin/nixos-rebuild", "switch", "--upgrade"]) .args(["/run/current-system/sw/bin/nixos-rebuild", "switch", "--upgrade"])
.check_run()?; .check_run()?;
if ctx.config().cleanup() { if ctx.config().cleanup() {
ctx.run_type() ctx.run_type()
.execute(&sudo) .execute(&sudo)
.args(&["/run/current-system/sw/bin/nix-collect-garbage", "-d"]) .args(["/run/current-system/sw/bin/nix-collect-garbage", "-d"])
.check_run()?; .check_run()?;
} }
} else { } else {
@@ -553,7 +553,7 @@ pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> {
run_type run_type
.execute(&flatpak) .execute(&flatpak)
.args(&["update", "--user", "-y"]) .args(["update", "--user", "-y"])
.check_run()?; .check_run()?;
print_separator("Flatpak System Packages"); print_separator("Flatpak System Packages");
@@ -561,12 +561,12 @@ pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> {
run_type run_type
.execute(sudo) .execute(sudo)
.arg(flatpak) .arg(flatpak)
.args(&["update", "--system", "-y"]) .args(["update", "--system", "-y"])
.check_run() .check_run()
} else { } else {
run_type run_type
.execute(&flatpak) .execute(&flatpak)
.args(&["update", "--system", "-y"]) .args(["update", "--system", "-y"])
.check_run() .check_run()
} }
} }

View File

@@ -10,15 +10,15 @@ pub fn run_macports(ctx: &ExecutionContext) -> Result<()> {
require("port")?; require("port")?;
let sudo = ctx.sudo().as_ref().unwrap(); let sudo = ctx.sudo().as_ref().unwrap();
print_separator("MacPorts"); 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() ctx.run_type()
.execute(sudo) .execute(sudo)
.args(&["port", "-u", "upgrade", "outdated"]) .args(["port", "-u", "upgrade", "outdated"])
.check_run()?; .check_run()?;
if ctx.config().cleanup() { if ctx.config().cleanup() {
ctx.run_type() ctx.run_type()
.execute(sudo) .execute(sudo)
.args(&["port", "-N", "reclaim"]) .args(["port", "-N", "reclaim"])
.check_run()?; .check_run()?;
} }
@@ -58,7 +58,7 @@ pub fn upgrade_macos(ctx: &ExecutionContext) -> Result<()> {
} }
let mut command = ctx.run_type().execute("softwareupdate"); let mut command = ctx.run_type().execute("softwareupdate");
command.args(&["--install", "--all"]); command.args(["--install", "--all"]);
if should_ask { if should_ask {
command.arg("--no-scan"); command.arg("--no-scan");

View File

@@ -74,7 +74,7 @@ pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
print_separator("Fisher"); 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<()> { pub fn run_bashit(ctx: &ExecutionContext) -> Result<()> {
@@ -84,7 +84,7 @@ pub fn run_bashit(ctx: &ExecutionContext) -> Result<()> {
ctx.run_type() ctx.run_type()
.execute("bash") .execute("bash")
.args(&["-lic", &format!("bash-it update {}", ctx.config().bashit_branch())]) .args(["-lic", &format!("bash-it update {}", ctx.config().bashit_branch())])
.check_run() .check_run()
} }
@@ -97,7 +97,7 @@ pub fn run_oh_my_fish(ctx: &ExecutionContext) -> Result<()> {
print_separator("oh-my-fish"); 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<()> { pub fn run_pkgin(ctx: &ExecutionContext) -> Result<()> {
@@ -127,7 +127,7 @@ pub fn run_fish_plug(ctx: &ExecutionContext) -> Result<()> {
print_separator("fish-plug"); 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<()> { 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).arg("update").check_run()?;
variant variant
.execute(run_type) .execute(run_type)
.args(&["upgrade", "--ignore-pinned", "--formula"]) .args(["upgrade", "--ignore-pinned", "--formula"])
.check_run()?; .check_run()?;
if ctx.config().cleanup() { if ctx.config().cleanup() {
@@ -156,19 +156,19 @@ pub fn run_brew_cask(ctx: &ExecutionContext, variant: BrewVariant) -> Result<()>
let cask_upgrade_exists = variant let cask_upgrade_exists = variant
.execute(RunType::Wet) .execute(RunType::Wet)
.args(&["--repository", "buo/cask-upgrade"]) .args(["--repository", "buo/cask-upgrade"])
.check_output() .check_output()
.map(|p| Path::new(p.trim()).exists())?; .map(|p| Path::new(p.trim()).exists())?;
let mut brew_args = vec![]; let mut brew_args = vec![];
if cask_upgrade_exists { if cask_upgrade_exists {
brew_args.extend(&["cu", "-y"]); brew_args.extend(["cu", "-y"]);
if ctx.config().brew_cask_greedy() { if ctx.config().brew_cask_greedy() {
brew_args.push("-a"); brew_args.push("-a");
} }
} else { } else {
brew_args.extend(&["upgrade", "--cask"]); brew_args.extend(["upgrade", "--cask"]);
if ctx.config().brew_cask_greedy() { if ctx.config().brew_cask_greedy() {
brew_args.push("--greedy"); brew_args.push("--greedy");
} }
@@ -205,10 +205,7 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
if multi_user { if multi_user {
if let Some(sudo) = ctx.sudo() { if let Some(sudo) = ctx.sudo() {
run_type run_type.execute(&sudo).args(["-i", "nix", "upgrade-nix"]).check_run()?;
.execute(&sudo)
.args(&["-i", "nix", "upgrade-nix"])
.check_run()?;
} else { } else {
print_warning("Need sudo to upgrade Nix"); 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()); 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<()> { 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!"); print_separator("SDKMAN!");
let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path); let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path);
run_type run_type.execute(&bash).args(["-c", &cmd_selfupdate]).check_run()?;
.execute(&bash)
.args(&["-c", cmd_selfupdate.as_str()])
.check_run()?;
let cmd_update = format!("source {} && sdk update", &sdkman_init_path); 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); let cmd_upgrade = format!("source {} && sdk upgrade", &sdkman_init_path);
run_type run_type.execute(&bash).args(["-c", &cmd_upgrade]).check_run()?;
.execute(&bash)
.args(&["-c", cmd_upgrade.as_str()])
.check_run()?;
if cleanup { if cleanup {
let cmd_flush_archives = format!("source {} && sdk flush archives", &sdkman_init_path); let cmd_flush_archives = format!("source {} && sdk flush archives", &sdkman_init_path);
run_type run_type.execute(&bash).args(["-c", &cmd_flush_archives]).check_run()?;
.execute(&bash)
.args(&["-c", cmd_flush_archives.as_str()])
.check_run()?;
let cmd_flush_temp = format!("source {} && sdk flush temp", &sdkman_init_path); let cmd_flush_temp = format!("source {} && sdk flush temp", &sdkman_init_path);
run_type run_type.execute(&bash).args(["-c", &cmd_flush_temp]).check_run()?;
.execute(&bash)
.args(&["-c", cmd_flush_temp.as_str()])
.check_run()?;
} }
Ok(()) Ok(())

View File

@@ -40,7 +40,7 @@ pub fn run_winget(ctx: &ExecutionContext) -> Result<()> {
print_separator("winget"); 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<()> { 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"); 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 { if cleanup {
run_type.execute(&scoop).args(&["cleanup", "*"]).check_run()?; run_type.execute(&scoop).args(["cleanup", "*"]).check_run()?;
} }
Ok(()) Ok(())
@@ -61,13 +61,13 @@ pub fn run_scoop(cleanup: bool, run_type: RunType) -> Result<()> {
pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> { pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
let wsl = require("wsl")?; let wsl = require("wsl")?;
let topgrade = Command::new(&wsl) let topgrade = Command::new(&wsl)
.args(&["bash", "-lc", "which topgrade"]) .args(["bash", "-lc", "which topgrade"])
.check_output() .check_output()
.map_err(|_| SkipStep(String::from("Could not find Topgrade installed in WSL")))?; .map_err(|_| SkipStep(String::from("Could not find Topgrade installed in WSL")))?;
let mut command = ctx.run_type().execute(&wsl); let mut command = ctx.run_type().execute(&wsl);
command command
.args(&["bash", "-c"]) .args(["bash", "-c"])
.arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade)); .arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade));
if ctx.config().yes() { if ctx.config().yes() {
@@ -94,7 +94,7 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
} }
pub fn reboot() { 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<()> { pub fn insert_startup_scripts(ctx: &ExecutionContext, git_repos: &mut Repositories) -> Result<()> {

View File

@@ -23,7 +23,7 @@ impl Powershell {
let profile = path.as_ref().and_then(|path| { let profile = path.as_ref().and_then(|path| {
Command::new(path) Command::new(path)
.args(&["-NoProfile", "-Command", "Split-Path $profile"]) .args(["-NoProfile", "-Command", "Split-Path $profile"])
.check_output() .check_output()
.map(|output| PathBuf::from(output.trim())) .map(|output| PathBuf::from(output.trim()))
.and_then(|p| p.require()) .and_then(|p| p.require())
@@ -44,7 +44,7 @@ impl Powershell {
#[cfg(windows)] #[cfg(windows)]
pub fn has_module(powershell: &Path, command: &str) -> bool { pub fn has_module(powershell: &Path, command: &str) -> bool {
Command::new(&powershell) Command::new(&powershell)
.args(&[ .args([
"-NoProfile", "-NoProfile",
"-Command", "-Command",
&format!("Get-Module -ListAvailable {}", command), &format!("Get-Module -ListAvailable {}", command),
@@ -76,7 +76,7 @@ impl Powershell {
println!("Updating modules..."); println!("Updating modules...");
ctx.run_type() ctx.run_type()
.execute(&powershell) .execute(&powershell)
.args(&["-NoProfile", "-Command", &cmd.join(" ")]) .args(["-NoProfile", "-Command", &cmd.join(" ")])
.check_run() .check_run()
} }
@@ -103,7 +103,7 @@ impl Powershell {
}; };
command command
.args(&[ .args([
"-NoProfile", "-NoProfile",
"-Command", "-Command",
&format!( &format!(

View File

@@ -17,7 +17,7 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
} }
let env = format!("TOPGRADE_PREFIX={}", hostname); let env = format!("TOPGRADE_PREFIX={}", hostname);
args.extend(&["env", &env, "$SHELL", "-lc", topgrade]); args.extend(["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().yes() { if ctx.config().yes() {
args.push("-y"); args.push("-y");
@@ -45,7 +45,7 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
} }
let env = format!("TOPGRADE_PREFIX={}", hostname); let env = format!("TOPGRADE_PREFIX={}", hostname);
args.extend(&["env", &env, "$SHELL", "-lc", topgrade]); args.extend(["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().yes() { if ctx.config().yes() {
args.push("-y"); args.push("-y");

View File

@@ -110,7 +110,7 @@ impl<'a> TemporaryPowerOn<'a> {
ctx.run_type() ctx.run_type()
.execute(vagrant) .execute(vagrant)
.args(&[subcommand, &vagrant_box.name]) .args([subcommand, &vagrant_box.name])
.current_dir(vagrant_box.path.clone()) .current_dir(vagrant_box.path.clone())
.check_run()?; .check_run()?;
Ok(TemporaryPowerOn { Ok(TemporaryPowerOn {
@@ -137,7 +137,7 @@ impl<'a> Drop for TemporaryPowerOn<'a> {
self.ctx self.ctx
.run_type() .run_type()
.execute(self.vagrant) .execute(self.vagrant)
.args(&[subcommand, &self.vagrant_box.name]) .args([subcommand, &self.vagrant_box.name])
.current_dir(self.vagrant_box.path.clone()) .current_dir(self.vagrant_box.path.clone())
.check_run() .check_run()
.ok(); .ok();
@@ -195,6 +195,6 @@ pub fn topgrade_vagrant_box(ctx: &ExecutionContext, vagrant_box: &VagrantBox) ->
ctx.run_type() ctx.run_type()
.execute(&vagrant.path) .execute(&vagrant.path)
.current_dir(&vagrant_box.path) .current_dir(&vagrant_box.path)
.args(&["ssh", "-c", &command]) .args(["ssh", "-c", &command])
.check_run() .check_run()
} }

View File

@@ -49,7 +49,7 @@ impl Tmux {
fn has_session(&self, session_name: &str) -> Result<bool, io::Error> { fn has_session(&self, session_name: &str) -> Result<bool, io::Error> {
Ok(self Ok(self
.build() .build()
.args(&["has-session", "-t", session_name]) .args(["has-session", "-t", session_name])
.output()? .output()?
.status .status
.success()) .success())
@@ -58,7 +58,7 @@ impl Tmux {
fn new_session(&self, session_name: &str) -> Result<bool, io::Error> { fn new_session(&self, session_name: &str) -> Result<bool, io::Error> {
Ok(self Ok(self
.build() .build()
.args(&["new-session", "-d", "-s", session_name, "-n", "dummy"]) .args(["new-session", "-d", "-s", session_name, "-n", "dummy"])
.spawn()? .spawn()?
.wait()? .wait()?
.success()) .success())
@@ -66,7 +66,7 @@ impl Tmux {
fn run_in_session(&self, command: &str) -> Result<()> { fn run_in_session(&self, command: &str) -> Result<()> {
self.build() self.build()
.args(&["new-window", "-t", "topgrade", command]) .args(["new-window", "-t", "topgrade", command])
.spawn()? .spawn()?
.wait()? .wait()?
.check()?; .check()?;
@@ -94,12 +94,12 @@ pub fn run_in_tmux(args: &Option<String>) -> ! {
tmux.run_in_session(&command).expect("Error running topgrade in tmux"); tmux.run_in_session(&command).expect("Error running topgrade in tmux");
tmux.build() tmux.build()
.args(&["kill-window", "-t", "topgrade:dummy"]) .args(["kill-window", "-t", "topgrade:dummy"])
.output() .output()
.expect("Error killing the dummy tmux window"); .expect("Error killing the dummy tmux window");
if env::var("TMUX").is_err() { 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); panic!("{:?}", err);
} else { } else {
println!("Topgrade launched in a new tmux session"); println!("Topgrade launched in a new tmux session");
@@ -110,7 +110,7 @@ pub fn run_in_tmux(args: &Option<String>) -> ! {
pub fn run_command(ctx: &ExecutionContext, command: &str) -> Result<()> { pub fn run_command(ctx: &ExecutionContext, command: &str) -> Result<()> {
Tmux::new(ctx.config().tmux_arguments()) Tmux::new(ctx.config().tmux_arguments())
.build() .build()
.args(&["new-window", "-a", "-t", "topgrade:1", command]) .args(["new-window", "-a", "-t", "topgrade:1", command])
.env_remove("TMUX") .env_remove("TMUX")
.spawn()? .spawn()?
.wait()? .wait()?

View File

@@ -48,9 +48,9 @@ fn upgrade(vim: &Path, vimrc: &Path, ctx: &ExecutionContext) -> Result<()> {
let output = ctx let output = ctx
.run_type() .run_type()
.execute(&vim) .execute(&vim)
.args(&["-u"]) .arg("-u")
.arg(vimrc) .arg(vimrc)
.args(&["-U", "NONE", "-V1", "-nNesS"]) .args(["-U", "NONE", "-V1", "-nNesS"])
.arg(tempfile.path()) .arg(tempfile.path())
.output()?; .output()?;

View File

@@ -19,7 +19,7 @@ pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
print_separator("zr"); print_separator("zr");
let cmd = format!("source {} && zr --update", zshrc(base_dirs).display()); 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 { 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"); print_separator("antigen");
let cmd = format!("source {} && antigen selfupdate && antigen update", zshrc.display()); 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<()> { 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"); 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<()> { 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"); print_separator("zinit");
let cmd = format!("source {} && zinit self-update && zinit update --all", zshrc.display(),); 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<()> { 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") env::var("ZIM_HOME")
.or_else(|_| { .or_else(|_| {
Command::new("zsh") Command::new("zsh")
.args(&["-c", "[[ -n ${ZIM_HOME} ]] && print -n ${ZIM_HOME}"]) .args(["-c", "[[ -n ${ZIM_HOME} ]] && print -n ${ZIM_HOME}"])
.check_output() .check_output()
}) })
.map(PathBuf::from) .map(PathBuf::from)
@@ -96,7 +96,7 @@ pub fn run_zim(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
run_type run_type
.execute(zsh) .execute(zsh)
.args(&["-i", "-c", "zimfw upgrade && zimfw update"]) .args(["-i", "-c", "zimfw upgrade && zimfw update"])
.check_run() .check_run()
} }
@@ -109,7 +109,7 @@ pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> {
let custom_dir = env::var::<_>("ZSH_CUSTOM") let custom_dir = env::var::<_>("ZSH_CUSTOM")
.or_else(|_| { .or_else(|_| {
Command::new("zsh") Command::new("zsh")
.args(&["-c", "test $ZSH_CUSTOM && echo -n $ZSH_CUSTOM"]) .args(["-c", "test $ZSH_CUSTOM && echo -n $ZSH_CUSTOM"])
.check_output() .check_output()
}) })
.map(PathBuf::from) .map(PathBuf::from)

View File

@@ -97,7 +97,7 @@ impl Terminal {
if let Some(timeout) = timeout { if let Some(timeout) = timeout {
command.arg("-t"); command.arg("-t");
command.arg(format!("{}", timeout.as_millis())); command.arg(format!("{}", timeout.as_millis()));
command.args(&["-a", "Topgrade"]); command.args(["-a", "Topgrade"]);
command.arg(message.as_ref()); command.arg(message.as_ref());
} }
command.output().ok(); command.output().ok();
@@ -229,18 +229,18 @@ impl Terminal {
let answer = loop { let answer = loop {
match self.term.read_key() { match self.term.read_key() {
Ok(Key::Char('y')) | Ok(Key::Char('Y')) => break Ok(true), Ok(Key::Char('y' | 'Y')) => break Ok(true),
Ok(Key::Char('s')) | Ok(Key::Char('S')) => { Ok(Key::Char('s' | 'S')) => {
println!("\n\nDropping you to shell. Fix what you need and then exit the shell.\n"); println!("\n\nDropping you to shell. Fix what you need and then exit the shell.\n");
run_shell(); run_shell();
break Ok(true); 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) => { Err(e) => {
error!("Error reading from terminal: {}", e); error!("Error reading from terminal: {}", e);
break Ok(false); 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)),
_ => (), _ => (),
} }
}; };

View File

@@ -136,9 +136,5 @@ pub fn require<T: AsRef<OsStr> + Debug>(binary_name: T) -> Result<PathBuf> {
#[allow(dead_code)] #[allow(dead_code)]
pub fn require_option<T>(option: Option<T>, cause: String) -> Result<T> { pub fn require_option<T>(option: Option<T>, cause: String) -> Result<T> {
if let Some(value) = option { option.ok_or_else(|| SkipStep(cause).into())
Ok(value)
} else {
Err(SkipStep(cause).into())
}
} }