Don't pass dry_run as a boolean to functions

This commit is contained in:
Roey Darwish Dror
2018-12-31 13:26:17 +02:00
parent 23ae157c72
commit 957d73c634
13 changed files with 257 additions and 196 deletions

View File

@@ -73,7 +73,7 @@ fn run() -> Result<(), Error> {
#[cfg(feature = "self-update")]
{
if !opt.dry_run && env::var("TOPGRADE_NO_SELF_UPGRADE").is_err() {
if !opt.run_type.dry() && env::var("TOPGRADE_NO_SELF_UPGRADE").is_err() {
if let Err(e) = self_update::self_update() {
print_warning(format!("Self update error: {}", e));
if let Some(cause) = e.cause() {
@@ -85,7 +85,7 @@ fn run() -> Result<(), Error> {
if let Some(commands) = config.pre_commands() {
for (name, command) in commands {
generic::run_custom_command(&name, &command, opt.dry_run).context(ErrorKind::PreCommand)?;
generic::run_custom_command(&name, &command, opt.run_type).context(ErrorKind::PreCommand)?;
}
}
@@ -93,7 +93,7 @@ fn run() -> Result<(), Error> {
let powershell = windows::Powershell::new();
#[cfg(windows)]
report.push_result(execute(|| powershell.update_modules(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| powershell.update_modules(opt.run_type), opt.no_retry)?);
#[cfg(target_os = "linux")]
let distribution = linux::Distribution::detect();
@@ -104,7 +104,7 @@ fn run() -> Result<(), Error> {
match &distribution {
Ok(distribution) => {
report.push_result(execute(
|| distribution.upgrade(&sudo, opt.cleanup, opt.dry_run),
|| distribution.upgrade(&sudo, opt.cleanup, opt.run_type),
opt.no_retry,
)?);
}
@@ -112,22 +112,22 @@ fn run() -> Result<(), Error> {
println!("Error detecting current distribution: {}", e);
}
}
report.push_result(execute(|| linux::run_etc_update(&sudo, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| linux::run_etc_update(&sudo, opt.run_type), opt.no_retry)?);
}
}
#[cfg(windows)]
report.push_result(execute(|| windows::run_chocolatey(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| windows::run_chocolatey(opt.run_type), opt.no_retry)?);
#[cfg(windows)]
report.push_result(execute(|| windows::run_scoop(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| windows::run_scoop(opt.run_type), opt.no_retry)?);
#[cfg(unix)]
report.push_result(execute(|| unix::run_homebrew(opt.cleanup, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| unix::run_homebrew(opt.cleanup, opt.run_type), opt.no_retry)?);
#[cfg(target_os = "freebsd")]
report.push_result(execute(|| freebsd::upgrade_packages(&sudo, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| freebsd::upgrade_packages(&sudo, opt.run_type), opt.no_retry)?);
#[cfg(unix)]
report.push_result(execute(|| unix::run_nix(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| unix::run_nix(opt.run_type), opt.no_retry)?);
if !opt.no_emacs {
git_repos.insert(base_dirs.home_dir().join(".emacs.d"));
@@ -162,42 +162,42 @@ fn run() -> Result<(), Error> {
}
}
for repo in git_repos.repositories() {
report.push_result(execute(|| git.pull(&repo, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| git.pull(&repo, opt.run_type), opt.no_retry)?);
}
#[cfg(unix)]
{
report.push_result(execute(|| unix::run_zplug(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| unix::run_fisher(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| tmux::run_tpm(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| unix::run_zplug(&base_dirs, opt.run_type), opt.no_retry)?);
report.push_result(execute(|| unix::run_fisher(&base_dirs, opt.run_type), opt.no_retry)?);
report.push_result(execute(|| tmux::run_tpm(&base_dirs, opt.run_type), opt.no_retry)?);
}
report.push_result(execute(|| generic::run_rustup(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_cargo_update(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_rustup(&base_dirs, opt.run_type), opt.no_retry)?);
report.push_result(execute(|| generic::run_cargo_update(opt.run_type), opt.no_retry)?);
if !opt.no_emacs {
report.push_result(execute(|| generic::run_emacs(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_emacs(&base_dirs, opt.run_type), opt.no_retry)?);
}
report.push_result(execute(|| generic::run_opam_update(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_vcpkg_update(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_pipx_update(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_jetpack(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_opam_update(opt.run_type), opt.no_retry)?);
report.push_result(execute(|| generic::run_vcpkg_update(opt.run_type), opt.no_retry)?);
report.push_result(execute(|| generic::run_pipx_update(opt.run_type), opt.no_retry)?);
report.push_result(execute(|| generic::run_jetpack(opt.run_type), opt.no_retry)?);
if !opt.no_vim {
report.push_result(execute(|| vim::upgrade_vim(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| vim::upgrade_neovim(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| vim::upgrade_vim(&base_dirs, opt.run_type), opt.no_retry)?);
report.push_result(execute(|| vim::upgrade_neovim(&base_dirs, opt.run_type), opt.no_retry)?);
}
report.push_result(execute(
|| node::run_npm_upgrade(&base_dirs, opt.dry_run),
|| node::run_npm_upgrade(&base_dirs, opt.run_type),
opt.no_retry,
)?);
report.push_result(execute(
|| generic::run_composer_update(&base_dirs, opt.dry_run),
|| generic::run_composer_update(&base_dirs, opt.run_type),
opt.no_retry,
)?);
report.push_result(execute(|| node::yarn_global_update(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| node::yarn_global_update(opt.run_type), opt.no_retry)?);
#[cfg(not(any(
target_os = "freebsd",
@@ -205,23 +205,23 @@ fn run() -> Result<(), Error> {
target_os = "netbsd",
target_os = "dragonfly"
)))]
report.push_result(execute(|| generic::run_apm(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_gem(&base_dirs, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| generic::run_apm(opt.run_type), opt.no_retry)?);
report.push_result(execute(|| generic::run_gem(&base_dirs, opt.run_type), opt.no_retry)?);
#[cfg(target_os = "linux")]
{
report.push_result(execute(|| linux::flatpak_user_update(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| linux::flatpak_user_update(opt.run_type), opt.no_retry)?);
report.push_result(execute(
|| linux::flatpak_global_update(&sudo, opt.dry_run),
|| linux::flatpak_global_update(&sudo, opt.run_type),
opt.no_retry,
)?);
report.push_result(execute(|| linux::run_snap(&sudo, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| linux::run_snap(&sudo, opt.run_type), opt.no_retry)?);
}
if let Some(commands) = config.commands() {
for (name, command) in commands {
report.push_result(execute(
|| Some((name, generic::run_custom_command(&name, &command, opt.dry_run).is_ok())),
|| Some((name, generic::run_custom_command(&name, &command, opt.run_type).is_ok())),
opt.no_retry,
)?);
}
@@ -229,28 +229,28 @@ fn run() -> Result<(), Error> {
#[cfg(target_os = "linux")]
{
report.push_result(execute(|| linux::run_fwupdmgr(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| linux::run_needrestart(&sudo, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| linux::run_fwupdmgr(opt.run_type), opt.no_retry)?);
report.push_result(execute(|| linux::run_needrestart(&sudo, opt.run_type), opt.no_retry)?);
}
#[cfg(target_os = "macos")]
{
if !opt.no_system {
report.push_result(execute(|| macos::upgrade_macos(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| macos::upgrade_macos(opt.run_type), opt.no_retry)?);
}
}
#[cfg(target_os = "freebsd")]
{
if !opt.no_system {
report.push_result(execute(|| freebsd::upgrade_freebsd(&sudo, opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| freebsd::upgrade_freebsd(&sudo, opt.run_type), opt.no_retry)?);
}
}
#[cfg(windows)]
{
if !opt.no_system {
report.push_result(execute(|| powershell.windows_update(opt.dry_run), opt.no_retry)?);
report.push_result(execute(|| powershell.windows_update(opt.run_type), opt.no_retry)?);
}
}