Add --no-retry (fix #97)
This commit is contained in:
@@ -95,6 +95,7 @@ Just run `topgrade`. It will run the following steps:
|
|||||||
* `--no-system` - Skip the system upgrade phase.
|
* `--no-system` - Skip the system upgrade phase.
|
||||||
* `--no-git-repos` - Don't pull custom git repositories.
|
* `--no-git-repos` - Don't pull custom git repositories.
|
||||||
* `--no-emacs` - Don't upgrade Emacs packages or configuration files.
|
* `--no-emacs` - Don't upgrade Emacs packages or configuration files.
|
||||||
|
* `--no-retry` - Don't ask to retry failed steps.
|
||||||
|
|
||||||
## Customization
|
## Customization
|
||||||
You can place a configuration file at `~/.config/topgrade.toml` (on macOS `~/Library/Preferences/topgrade.toml`).. Here's an example:
|
You can place a configuration file at `~/.config/topgrade.toml` (on macOS `~/Library/Preferences/topgrade.toml`).. Here's an example:
|
||||||
|
|||||||
@@ -73,4 +73,8 @@ pub struct Opt {
|
|||||||
/// Print what would be done
|
/// Print what would be done
|
||||||
#[structopt(short = "n", long = "dry-run")]
|
#[structopt(short = "n", long = "dry-run")]
|
||||||
pub dry_run: bool,
|
pub dry_run: bool,
|
||||||
|
|
||||||
|
/// Do not ask to retry failed steps
|
||||||
|
#[structopt(long = "no-retry")]
|
||||||
|
pub no_retry: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
89
src/main.rs
89
src/main.rs
@@ -67,7 +67,7 @@ struct NoBaseDirectories;
|
|||||||
#[fail(display = "Process Interrupted")]
|
#[fail(display = "Process Interrupted")]
|
||||||
pub struct Interrupted;
|
pub struct Interrupted;
|
||||||
|
|
||||||
fn execute<'a, F, M>(func: F) -> Result<Option<(M, bool)>, Error>
|
fn execute<'a, F, M>(func: F, no_retry: bool) -> Result<Option<(M, bool)>, Error>
|
||||||
where
|
where
|
||||||
M: Into<Cow<'a, str>>,
|
M: Into<Cow<'a, str>>,
|
||||||
F: Fn() -> Option<(M, bool)>,
|
F: Fn() -> Option<(M, bool)>,
|
||||||
@@ -82,7 +82,8 @@ where
|
|||||||
ctrlc::set_running(true);
|
ctrlc::set_running(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let should_retry = should_retry(running).map_err(|e| {
|
let should_ask = !running || !no_retry;
|
||||||
|
let should_retry = should_ask && should_retry(running).map_err(|e| {
|
||||||
if e.kind() == ErrorKind::Interrupted {
|
if e.kind() == ErrorKind::Interrupted {
|
||||||
Error::from(Interrupted)
|
Error::from(Interrupted)
|
||||||
} else {
|
} else {
|
||||||
@@ -141,7 +142,7 @@ fn run() -> Result<(), Error> {
|
|||||||
let powershell = windows::Powershell::new();
|
let powershell = windows::Powershell::new();
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
report.push_result(execute(|| powershell.update_modules(opt.dry_run))?);
|
report.push_result(execute(|| powershell.update_modules(opt.dry_run), opt.no_retry)?);
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let distribution = linux::Distribution::detect();
|
let distribution = linux::Distribution::detect();
|
||||||
@@ -151,28 +152,28 @@ fn run() -> Result<(), Error> {
|
|||||||
if !opt.no_system {
|
if !opt.no_system {
|
||||||
match &distribution {
|
match &distribution {
|
||||||
Ok(distribution) => {
|
Ok(distribution) => {
|
||||||
report.push_result(execute(|| distribution.upgrade(&sudo, opt.dry_run))?);
|
report.push_result(execute(|| distribution.upgrade(&sudo, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Error detecting current distribution: {}", e);
|
println!("Error detecting current distribution: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
report.push_result(execute(|| linux::run_etc_update(&sudo, opt.dry_run))?);
|
report.push_result(execute(|| linux::run_etc_update(&sudo, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
report.push_result(execute(|| windows::run_chocolatey(opt.dry_run))?);
|
report.push_result(execute(|| windows::run_chocolatey(opt.dry_run), opt.no_retry)?);
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
report.push_result(execute(|| windows::run_scoop(opt.dry_run))?);
|
report.push_result(execute(|| windows::run_scoop(opt.dry_run), opt.no_retry)?);
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
report.push_result(execute(|| unix::run_homebrew(opt.cleanup, opt.dry_run))?);
|
report.push_result(execute(|| unix::run_homebrew(opt.cleanup, opt.dry_run), opt.no_retry)?);
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
report.push_result(execute(|| freebsd::upgrade_packages(&sudo, opt.dry_run))?);
|
report.push_result(execute(|| freebsd::upgrade_packages(&sudo, opt.dry_run), opt.no_retry)?);
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
report.push_result(execute(|| unix::run_nix(opt.dry_run))?);
|
report.push_result(execute(|| unix::run_nix(opt.dry_run), opt.no_retry)?);
|
||||||
|
|
||||||
if !opt.no_emacs {
|
if !opt.no_emacs {
|
||||||
git_repos.insert(base_dirs.home_dir().join(".emacs.d"));
|
git_repos.insert(base_dirs.home_dir().join(".emacs.d"));
|
||||||
@@ -205,32 +206,38 @@ fn run() -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for repo in git_repos.repositories() {
|
for repo in git_repos.repositories() {
|
||||||
report.push_result(execute(|| git.pull(&repo, opt.dry_run))?);
|
report.push_result(execute(|| git.pull(&repo, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
report.push_result(execute(|| unix::run_zplug(&base_dirs, opt.dry_run))?);
|
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))?);
|
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))?);
|
report.push_result(execute(|| tmux::run_tpm(&base_dirs, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
report.push_result(execute(|| generic::run_rustup(&base_dirs, opt.dry_run))?);
|
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))?);
|
report.push_result(execute(|| generic::run_cargo_update(opt.dry_run), opt.no_retry)?);
|
||||||
|
|
||||||
if !opt.no_emacs {
|
if !opt.no_emacs {
|
||||||
report.push_result(execute(|| generic::run_emacs(&base_dirs, opt.dry_run))?);
|
report.push_result(execute(|| generic::run_emacs(&base_dirs, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
report.push_result(execute(|| generic::run_opam_update(opt.dry_run))?);
|
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))?);
|
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))?);
|
report.push_result(execute(|| generic::run_pipx_update(opt.dry_run), opt.no_retry)?);
|
||||||
report.push_result(execute(|| generic::run_jetpack(opt.dry_run))?);
|
report.push_result(execute(|| generic::run_jetpack(opt.dry_run), opt.no_retry)?);
|
||||||
report.push_result(execute(|| vim::upgrade_vim(&base_dirs, opt.dry_run))?);
|
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))?);
|
report.push_result(execute(|| vim::upgrade_neovim(&base_dirs, opt.dry_run), opt.no_retry)?);
|
||||||
report.push_result(execute(|| node::run_npm_upgrade(&base_dirs, opt.dry_run))?);
|
report.push_result(execute(
|
||||||
report.push_result(execute(|| generic::run_composer_update(&base_dirs, opt.dry_run))?);
|
|| node::run_npm_upgrade(&base_dirs, opt.dry_run),
|
||||||
report.push_result(execute(|| node::yarn_global_update(opt.dry_run))?);
|
opt.no_retry,
|
||||||
|
)?);
|
||||||
|
report.push_result(execute(
|
||||||
|
|| generic::run_composer_update(&base_dirs, opt.dry_run),
|
||||||
|
opt.no_retry,
|
||||||
|
)?);
|
||||||
|
report.push_result(execute(|| node::yarn_global_update(opt.dry_run), opt.no_retry)?);
|
||||||
|
|
||||||
#[cfg(not(any(
|
#[cfg(not(any(
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
@@ -238,48 +245,52 @@ fn run() -> Result<(), Error> {
|
|||||||
target_os = "netbsd",
|
target_os = "netbsd",
|
||||||
target_os = "dragonfly"
|
target_os = "dragonfly"
|
||||||
)))]
|
)))]
|
||||||
report.push_result(execute(|| generic::run_apm(opt.dry_run))?);
|
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))?);
|
report.push_result(execute(|| generic::run_gem(&base_dirs, opt.dry_run), opt.no_retry)?);
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
report.push_result(execute(|| linux::flatpak_user_update(opt.dry_run))?);
|
report.push_result(execute(|| linux::flatpak_user_update(opt.dry_run), opt.no_retry)?);
|
||||||
report.push_result(execute(|| linux::flatpak_global_update(&sudo, opt.dry_run))?);
|
report.push_result(execute(
|
||||||
report.push_result(execute(|| linux::run_snap(&sudo, opt.dry_run))?);
|
|| linux::flatpak_global_update(&sudo, opt.dry_run),
|
||||||
|
opt.no_retry,
|
||||||
|
)?);
|
||||||
|
report.push_result(execute(|| linux::run_snap(&sudo, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(commands) = config.commands() {
|
if let Some(commands) = config.commands() {
|
||||||
for (name, command) in commands {
|
for (name, command) in commands {
|
||||||
report.push_result(execute(|| {
|
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.dry_run).is_ok())),
|
||||||
})?);
|
opt.no_retry,
|
||||||
|
)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
report.push_result(execute(|| linux::run_fwupdmgr(opt.dry_run))?);
|
report.push_result(execute(|| linux::run_fwupdmgr(opt.dry_run), opt.no_retry)?);
|
||||||
report.push_result(execute(|| linux::run_needrestart(&sudo, opt.dry_run))?);
|
report.push_result(execute(|| linux::run_needrestart(&sudo, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
if !opt.no_system {
|
if !opt.no_system {
|
||||||
report.push_result(execute(|| macos::upgrade_macos(opt.dry_run))?);
|
report.push_result(execute(|| macos::upgrade_macos(opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
{
|
{
|
||||||
if !opt.no_system {
|
if !opt.no_system {
|
||||||
report.push_result(execute(|| freebsd::upgrade_freebsd(&sudo, opt.dry_run))?);
|
report.push_result(execute(|| freebsd::upgrade_freebsd(&sudo, opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
if !opt.no_system {
|
if !opt.no_system {
|
||||||
report.push_result(execute(|| powershell.windows_update(opt.dry_run))?);
|
report.push_result(execute(|| powershell.windows_update(opt.dry_run), opt.no_retry)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user