diff --git a/src/internal/git/updater.rs b/src/internal/git/updater.rs index 4330cdc7..db94114e 100644 --- a/src/internal/git/updater.rs +++ b/src/internal/git/updater.rs @@ -378,7 +378,7 @@ pub fn update(options: &UpdateOptions) -> (HashSet, HashSet) { return (HashSet::new(), HashSet::new()); } - self_update(); + self_update(false); // Nothing more to do if nothing is in the omnipath, or if we are running // as sudo since we don't want the repositories to be updated in that case diff --git a/src/internal/self_updater.rs b/src/internal/self_updater.rs index 1346ede3..5fe0238c 100644 --- a/src/internal/self_updater.rs +++ b/src/internal/self_updater.rs @@ -181,17 +181,19 @@ pub fn compatible_release_os() -> Vec { } } -pub fn self_update() { - // Check if OMNI_SKIP_SELF_UPDATE is set - if let Some(skip_self_update) = std::env::var_os("OMNI_SKIP_SELF_UPDATE") { - if !skip_self_update.to_str().unwrap().is_empty() { - return; +pub fn self_update(force: bool) { + if !force { + // Check if OMNI_SKIP_SELF_UPDATE is set + if let Some(skip_self_update) = std::env::var_os("OMNI_SKIP_SELF_UPDATE") { + if !skip_self_update.to_str().unwrap().is_empty() { + return; + } } - } - let config = config("."); - if config.path_repo_updates.self_update.do_not_check() { - return; + let config = config("."); + if config.path_repo_updates.self_update.do_not_check() { + return; + } } if let Some(omni_release) = OmniRelease::latest() { diff --git a/src/main.rs b/src/main.rs index 751bd465..8a5b3e4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use internal::git::auto_update_async; use internal::git::auto_update_on_command_not_found; use internal::git::exec_update; use internal::git::exec_update_and_log_on_error; +use internal::self_updater::self_update; use internal::StringColor; #[derive(Debug, Clone)] @@ -43,31 +44,22 @@ impl MainArgs { .arg( clap::Arg::new("update") .long("update") - .conflicts_with("args") - .conflicts_with("exists") - .conflicts_with("help") - .conflicts_with("update-and-log-on-error") - .conflicts_with("version") .action(clap::ArgAction::SetTrue), ) .arg( clap::Arg::new("update-and-log-on-error") .long("update-and-log-on-error") - .conflicts_with("args") - .conflicts_with("exists") - .conflicts_with("help") - .conflicts_with("update") - .conflicts_with("version") + .action(clap::ArgAction::SetTrue), + ) + .arg( + clap::Arg::new("self-update") + .long("self-update") .action(clap::ArgAction::SetTrue), ) .arg( clap::Arg::new("exists") .long("exists") .short('e') - .conflicts_with("help") - .conflicts_with("update") - .conflicts_with("update-and-log-on-error") - .conflicts_with("version") .action(clap::ArgAction::SetTrue), ) .arg( @@ -75,24 +67,12 @@ impl MainArgs { .long("askpass") .short('A') .num_args(2) - .value_names(["prompt", "socket path"]) - .conflicts_with("args") - .conflicts_with("exists") - .conflicts_with("help") - .conflicts_with("update") - .conflicts_with("update-and-log-on-error") - .conflicts_with("version"), + .value_names(["prompt", "socket path"]), ) .arg( clap::Arg::new("local") .long("local") .short('l') - .conflicts_with("askpass") - .conflicts_with("exists") - .conflicts_with("help") - .conflicts_with("update") - .conflicts_with("update-and-log-on-error") - .conflicts_with("version") .action(clap::ArgAction::SetTrue), ) .arg( @@ -100,6 +80,20 @@ impl MainArgs { .action(clap::ArgAction::Append) .allow_hyphen_values(true), ) + .group( + clap::ArgGroup::new("exclusive-flags") + .args([ + "askpass", + "exists", + "help", + "local", + "self-update", + "update", + "update-and-log-on-error", + "version", + ]) + .multiple(false), + ) .try_get_matches_from(&parse_argv); let matches = match matches { @@ -146,7 +140,10 @@ impl MainArgs { } } - if *matches.get_one::("update").unwrap_or(&false) { + if *matches.get_one::("self-update").unwrap_or(&false) { + self_update(true); + exit(0); + } else if *matches.get_one::("update").unwrap_or(&false) { exec_update(); } else if *matches .get_one::("update-and-log-on-error")