Add no-self-update config and flag (#388)

This commit is contained in:
PolpOnline
2023-03-22 22:05:21 +01:00
committed by GitHub
parent 907465f891
commit 565aa405be
3 changed files with 16 additions and 1 deletions

View File

@@ -50,6 +50,9 @@
# Skip the preamble displayed when topgrade is run # Skip the preamble displayed when topgrade is run
#display_preamble = false #display_preamble = false
# Whether to self update (this is ignored if the binary has been built without self update support, available also via setting the environment variable TOPGRADE_NO_SELF_UPGRADE)
#no_self_update = true
[git] [git]
#max_concurrency = 5 #max_concurrency = 5
# Additional git repositories to pull # Additional git repositories to pull

View File

@@ -336,6 +336,7 @@ pub struct ConfigFile {
vagrant: Option<Vagrant>, vagrant: Option<Vagrant>,
flatpak: Option<Flatpak>, flatpak: Option<Flatpak>,
distrobox: Option<Distrobox>, distrobox: Option<Distrobox>,
no_self_update: Option<bool>,
} }
fn config_directory(base_dirs: &BaseDirs) -> PathBuf { fn config_directory(base_dirs: &BaseDirs) -> PathBuf {
@@ -522,6 +523,10 @@ pub struct CommandLineArgs {
/// Print roff manpage and exit /// Print roff manpage and exit
#[clap(long, hide = true)] #[clap(long, hide = true)]
pub gen_manpage: bool, pub gen_manpage: bool,
/// Don't update Topgrade
#[clap(long = "no-self-update")]
pub no_self_update: bool,
} }
impl CommandLineArgs { impl CommandLineArgs {
@@ -645,6 +650,11 @@ impl Config {
enabled_steps enabled_steps
} }
/// Tell whether we should run a self update.
pub fn no_self_update(&self) -> bool {
self.opt.no_self_update || self.config_file.no_self_update.unwrap_or(false)
}
/// Tell whether we should run in tmux. /// Tell whether we should run in tmux.
pub fn run_in_tmux(&self) -> bool { pub fn run_in_tmux(&self) -> bool {
self.opt.run_in_tmux || self.config_file.run_in_tmux.unwrap_or(false) self.opt.run_in_tmux || self.config_file.run_in_tmux.unwrap_or(false)

View File

@@ -116,7 +116,9 @@ For more information about this issue see https://askubuntu.com/questions/110969
#[cfg(feature = "self-update")] #[cfg(feature = "self-update")]
{ {
if !run_type.dry() && env::var("TOPGRADE_NO_SELF_UPGRADE").is_err() { let config_self_upgrade = env::var("TOPGRADE_NO_SELF_UPGRADE").is_err() && !config.no_self_update();
if !run_type.dry() && config_self_upgrade {
let result = self_update::self_update(); let result = self_update::self_update();
if let Err(e) = &result { if let Err(e) = &result {