refactor: Run cargo clippy --fix (#113)

This commit is contained in:
pan93412
2022-11-03 04:26:20 +08:00
committed by GitHub
parent 16a7d5f00b
commit a7c2262537
9 changed files with 52 additions and 52 deletions

View File

@@ -87,7 +87,7 @@ impl Emacs {
print_separator("Emacs"); print_separator("Emacs");
let mut command = ctx.run_type().execute(&emacs); let mut command = ctx.run_type().execute(emacs);
command command
.args(["--batch", "--debug-init", "-l"]) .args(["--batch", "--debug-init", "-l"])

View File

@@ -60,12 +60,12 @@ pub fn run_flutter_upgrade(run_type: RunType) -> Result<()> {
let flutter = utils::require("flutter")?; let flutter = utils::require("flutter")?;
print_separator("Flutter"); print_separator("Flutter");
run_type.execute(&flutter).arg("upgrade").check_run() run_type.execute(flutter).arg("upgrade").check_run()
} }
pub fn run_go(run_type: RunType) -> Result<()> { pub fn run_go(run_type: RunType) -> Result<()> {
let go = utils::require("go")?; 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 gopath = go_output.trim();
let go_global_update = utils::require("go-global-update") let go_global_update = utils::require("go-global-update")
@@ -74,7 +74,7 @@ pub fn run_go(run_type: RunType) -> Result<()> {
print_separator("Go"); print_separator("Go");
run_type.execute(&go_global_update).check_run() run_type.execute(go_global_update).check_run()
} }
pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
@@ -83,7 +83,7 @@ pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
print_separator("RubyGems"); print_separator("RubyGems");
let mut command = run_type.execute(&gem); let mut command = run_type.execute(gem);
command.arg("update"); command.arg("update");
if env::var_os("RBENV_SHELL").is_none() { if env::var_os("RBENV_SHELL").is_none() {
@@ -123,7 +123,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<()> {
@@ -131,7 +131,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<()> {
@@ -139,7 +139,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") {
@@ -160,7 +160,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<()> {
@@ -190,7 +190,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<()> {
@@ -199,7 +199,7 @@ pub fn run_gcloud_components_update(run_type: RunType) -> Result<()> {
print_separator("gcloud"); print_separator("gcloud");
run_type run_type
.execute(&gcloud) .execute(gcloud)
.args(["components", "update", "--quiet"]) .args(["components", "update", "--quiet"])
.check_run() .check_run()
} }
@@ -209,7 +209,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<()> {
@@ -217,7 +217,7 @@ pub fn run_rtcl(ctx: &ExecutionContext) -> Result<()> {
print_separator("rtcl"); print_separator("rtcl");
ctx.run_type().execute(&rupdate).check_run() ctx.run_type().execute(rupdate).check_run()
} }
pub fn run_opam_update(ctx: &ExecutionContext) -> Result<()> { pub fn run_opam_update(ctx: &ExecutionContext) -> Result<()> {
@@ -239,14 +239,14 @@ 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<()> {
let pipx = utils::require("pipx")?; let pipx = utils::require("pipx")?;
print_separator("pipx"); print_separator("pipx");
run_type.execute(&pipx).arg("upgrade-all").check_run() run_type.execute(pipx).arg("upgrade-all").check_run()
} }
pub fn run_conda_update(ctx: &ExecutionContext) -> Result<()> { pub fn run_conda_update(ctx: &ExecutionContext) -> Result<()> {
@@ -264,7 +264,7 @@ pub fn run_conda_update(ctx: &ExecutionContext) -> Result<()> {
print_separator("Conda"); print_separator("Conda");
ctx.run_type() ctx.run_type()
.execute(&conda) .execute(conda)
.args(["update", "--all", "-y"]) .args(["update", "--all", "-y"])
.check_run() .check_run()
} }
@@ -289,7 +289,7 @@ pub fn run_pip3_update(run_type: RunType) -> Result<()> {
} }
pub fn run_stack_update(run_type: RunType) -> Result<()> { pub fn run_stack_update(run_type: RunType) -> Result<()> {
if let Ok(_) = utils::require("ghcup") { if utils::require("ghcup").is_ok() {
// `ghcup` is present and probably(?) being used to install `stack`. // `ghcup` is present and probably(?) being used to install `stack`.
// Don't upgrade `stack`, let `ghcup` handle it. Per `ghcup install stack`: // Don't upgrade `stack`, let `ghcup` handle it. Per `ghcup install stack`:
// !!! Additionally, you should upgrade stack only through ghcup and not use 'stack upgrade' !!! // !!! Additionally, you should upgrade stack only through ghcup and not use 'stack upgrade' !!!
@@ -299,14 +299,14 @@ pub fn run_stack_update(run_type: RunType) -> Result<()> {
let stack = utils::require("stack")?; let stack = utils::require("stack")?;
print_separator("stack"); print_separator("stack");
run_type.execute(&stack).arg("upgrade").check_run() run_type.execute(stack).arg("upgrade").check_run()
} }
pub fn run_ghcup_update(run_type: RunType) -> Result<()> { pub fn run_ghcup_update(run_type: RunType) -> Result<()> {
let ghcup = utils::require("ghcup")?; let ghcup = utils::require("ghcup")?;
print_separator("ghcup"); print_separator("ghcup");
run_type.execute(&ghcup).arg("upgrade").check_run() run_type.execute(ghcup).arg("upgrade").check_run()
} }
pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> { pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> {
@@ -323,7 +323,7 @@ pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> {
let tlmgr_directory = { let tlmgr_directory = {
let mut d = PathBuf::from( let mut d = PathBuf::from(
std::str::from_utf8( std::str::from_utf8(
&Command::new(&kpsewhich) &Command::new(kpsewhich)
.arg("-var-value=SELFAUTOPARENT") .arg("-var-value=SELFAUTOPARENT")
.output()? .output()?
.stdout, .stdout,
@@ -360,7 +360,7 @@ pub fn run_chezmoi_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()>
print_separator("chezmoi"); print_separator("chezmoi");
run_type.execute(&chezmoi).arg("update").check_run() run_type.execute(chezmoi).arg("update").check_run()
} }
pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
@@ -440,7 +440,7 @@ pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
if stdout.contains("valet") || stderr.contains("valet") { if stdout.contains("valet") || stderr.contains("valet") {
if let Some(valet) = utils::which("valet") { if let Some(valet) = utils::which("valet") {
ctx.run_type().execute(&valet).arg("install").check_run()?; ctx.run_type().execute(valet).arg("install").check_run()?;
} }
} }
@@ -485,21 +485,21 @@ 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<()> {
let bin = utils::require("bin")?; let bin = utils::require("bin")?;
print_separator("Bin"); print_separator("Bin");
ctx.run_type().execute(&bin).arg("update").check_run() ctx.run_type().execute(bin).arg("update").check_run()
} }
pub fn spicetify_upgrade(ctx: &ExecutionContext) -> Result<()> { pub fn spicetify_upgrade(ctx: &ExecutionContext) -> Result<()> {
let spicetify = utils::require("spicetify")?; let spicetify = utils::require("spicetify")?;
print_separator("Spicetify"); print_separator("Spicetify");
ctx.run_type().execute(&spicetify).arg("upgrade").check_run() ctx.run_type().execute(spicetify).arg("upgrade").check_run()
} }
pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> { pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> {
@@ -523,7 +523,7 @@ pub fn update_julia_packages(ctx: &ExecutionContext) -> Result<()> {
print_separator("Julia Packages"); print_separator("Julia Packages");
ctx.run_type() ctx.run_type()
.execute(&julia) .execute(julia)
.args(["-e", "using Pkg; Pkg.update()"]) .args(["-e", "using Pkg; Pkg.update()"])
.check_run() .check_run()
} }

View File

@@ -13,7 +13,7 @@ pub fn upgrade_kak_plug(ctx: &ExecutionContext) -> Result<()> {
print_separator("Kakoune"); print_separator("Kakoune");
let mut command = ctx.run_type().execute(&kak); 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()?; let output = command.output()?;

View File

@@ -11,15 +11,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()?;
} }
@@ -52,7 +52,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");
@@ -81,12 +81,12 @@ pub fn run_sparkle(ctx: &ExecutionContext) -> Result<()> {
for application in (fs::read_dir("/Applications")?).flatten() { for application in (fs::read_dir("/Applications")?).flatten() {
let probe = Command::new(&sparkle) let probe = Command::new(&sparkle)
.args(&["--probe", "--application"]) .args(["--probe", "--application"])
.arg(application.path()) .arg(application.path())
.check_output(); .check_output();
if probe.is_ok() { if probe.is_ok() {
let mut command = ctx.run_type().execute(&sparkle); let mut command = ctx.run_type().execute(&sparkle);
command.args(&["bundle", "--check-immediately", "--application"]); command.args(["bundle", "--check-immediately", "--application"]);
command.arg(application.path()); command.arg(application.path());
command.spawn()?.wait()?; command.spawn()?.wait()?;
} }

View File

@@ -124,7 +124,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<()> {
@@ -154,7 +154,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()
} }
/// Upgrades `fundle` and `fundle` plugins. /// Upgrades `fundle` and `fundle` plugins.
@@ -258,19 +258,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");
} }
@@ -352,7 +352,7 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
} }
} }
run_type.execute(&nix_channel).arg("--update").check_run()?; run_type.execute(nix_channel).arg("--update").check_run()?;
if std::path::Path::new(&manifest_json_path).exists() { if std::path::Path::new(&manifest_json_path).exists() {
run_type run_type
@@ -371,7 +371,7 @@ pub fn run_yadm(ctx: &ExecutionContext) -> Result<()> {
print_separator("yadm"); print_separator("yadm");
ctx.run_type().execute(&yadm).arg("pull").check_run() ctx.run_type().execute(yadm).arg("pull").check_run()
} }
pub fn run_asdf(run_type: RunType) -> Result<()> { pub fn run_asdf(run_type: RunType) -> Result<()> {
@@ -392,21 +392,21 @@ pub fn run_home_manager(run_type: RunType) -> Result<()> {
let home_manager = require("home-manager")?; let home_manager = require("home-manager")?;
print_separator("home-manager"); print_separator("home-manager");
run_type.execute(&home_manager).arg("switch").check_run() run_type.execute(home_manager).arg("switch").check_run()
} }
pub fn run_tldr(run_type: RunType) -> Result<()> { pub fn run_tldr(run_type: RunType) -> Result<()> {
let tldr = require("tldr")?; let tldr = require("tldr")?;
print_separator("TLDR"); print_separator("TLDR");
run_type.execute(&tldr).arg("--update").check_run() run_type.execute(tldr).arg("--update").check_run()
} }
pub fn run_pearl(run_type: RunType) -> Result<()> { pub fn run_pearl(run_type: RunType) -> Result<()> {
let pearl = require("pearl")?; let pearl = require("pearl")?;
print_separator("pearl"); print_separator("pearl");
run_type.execute(&pearl).arg("update").check_run() run_type.execute(pearl).arg("update").check_run()
} }
pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Result<()> { pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Result<()> {
@@ -471,7 +471,7 @@ pub fn run_bun(ctx: &ExecutionContext) -> Result<()> {
print_separator("Bun"); print_separator("Bun");
ctx.run_type().execute(&bun).arg("upgrade").check_run() ctx.run_type().execute(bun).arg("upgrade").check_run()
} }
/// Update dotfiles with `rcm(7)`. /// Update dotfiles with `rcm(7)`.

View File

@@ -47,6 +47,6 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
print_separator(format!("Remote ({})", hostname)); print_separator(format!("Remote ({})", hostname));
println!("Connecting to {}...", hostname); println!("Connecting to {}...", hostname);
ctx.run_type().execute(&ssh).args(&args).check_run() ctx.run_type().execute(ssh).args(&args).check_run()
} }
} }

View File

@@ -20,7 +20,7 @@ pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
print_separator("tmux plugins"); print_separator("tmux plugins");
run_type.execute(&tpm).arg("all").check_run() run_type.execute(tpm).arg("all").check_run()
} }
struct Tmux { struct Tmux {

View File

@@ -118,9 +118,9 @@ pub fn upgrade_vim(base_dirs: &BaseDirs, ctx: &ExecutionContext) -> Result<()> {
upgrade( upgrade(
ctx.run_type() ctx.run_type()
.execute(&vim) .execute(&vim)
.args(&["-u"]) .args(["-u"])
.arg(vimrc) .arg(vimrc)
.args(&["-U", "NONE", "-V1", "-nNesS"]) .args(["-U", "NONE", "-V1", "-nNesS"])
.arg(upgrade_script()?.path()), .arg(upgrade_script()?.path()),
ctx, ctx,
) )
@@ -133,10 +133,10 @@ pub fn upgrade_neovim(base_dirs: &BaseDirs, ctx: &ExecutionContext) -> Result<()
print_separator("Neovim"); print_separator("Neovim");
upgrade( upgrade(
ctx.run_type() ctx.run_type()
.execute(&nvim) .execute(nvim)
.args(&["-u"]) .args(["-u"])
.arg(nvimrc) .arg(nvimrc)
.args(&["--headless", "-V1", "-nS"]) .args(["--headless", "-V1", "-nS"])
.arg(upgrade_script()?.path()), .arg(upgrade_script()?.path()),
ctx, ctx,
) )

View File

@@ -223,7 +223,7 @@ impl Terminal {
self.term.set_title("Topgrade - Awaiting user"); self.term.set_title("Topgrade - Awaiting user");
} }
self.notify_desktop(&format!("{} failed", step_name), None); self.notify_desktop(format!("{} failed", step_name), None);
self.term self.term
.write_fmt(format_args!( .write_fmt(format_args!(