Skip to content

Commit

Permalink
feat(self-update): add omni --self-update support (#898)
Browse files Browse the repository at this point in the history
This will only trigger updating omni itself if a new version is
available.

Closes #897
  • Loading branch information
xaf authored Jan 16, 2025
1 parent e14b995 commit 12f5d81
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/internal/git/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub fn update(options: &UpdateOptions) -> (HashSet<PathBuf>, HashSet<PathBuf>) {
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
Expand Down
20 changes: 11 additions & 9 deletions src/internal/self_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,19 @@ pub fn compatible_release_os() -> Vec<String> {
}
}

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() {
Expand Down
53 changes: 25 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -43,63 +44,56 @@ 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(
clap::Arg::new("askpass")
.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(
clap::Arg::new("args")
.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 {
Expand Down Expand Up @@ -146,7 +140,10 @@ impl MainArgs {
}
}

if *matches.get_one::<bool>("update").unwrap_or(&false) {
if *matches.get_one::<bool>("self-update").unwrap_or(&false) {
self_update(true);
exit(0);
} else if *matches.get_one::<bool>("update").unwrap_or(&false) {
exec_update();
} else if *matches
.get_one::<bool>("update-and-log-on-error")
Expand Down

0 comments on commit 12f5d81

Please sign in to comment.