Add no-self-update config and flag (#388)
This commit is contained in:
@@ -50,6 +50,9 @@
|
||||
# Skip the preamble displayed when topgrade is run
|
||||
#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]
|
||||
#max_concurrency = 5
|
||||
# Additional git repositories to pull
|
||||
|
||||
@@ -336,6 +336,7 @@ pub struct ConfigFile {
|
||||
vagrant: Option<Vagrant>,
|
||||
flatpak: Option<Flatpak>,
|
||||
distrobox: Option<Distrobox>,
|
||||
no_self_update: Option<bool>,
|
||||
}
|
||||
|
||||
fn config_directory(base_dirs: &BaseDirs) -> PathBuf {
|
||||
@@ -522,6 +523,10 @@ pub struct CommandLineArgs {
|
||||
/// Print roff manpage and exit
|
||||
#[clap(long, hide = true)]
|
||||
pub gen_manpage: bool,
|
||||
|
||||
/// Don't update Topgrade
|
||||
#[clap(long = "no-self-update")]
|
||||
pub no_self_update: bool,
|
||||
}
|
||||
|
||||
impl CommandLineArgs {
|
||||
@@ -645,6 +650,11 @@ impl Config {
|
||||
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.
|
||||
pub fn run_in_tmux(&self) -> bool {
|
||||
self.opt.run_in_tmux || self.config_file.run_in_tmux.unwrap_or(false)
|
||||
|
||||
@@ -116,7 +116,9 @@ For more information about this issue see https://askubuntu.com/questions/110969
|
||||
|
||||
#[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();
|
||||
|
||||
if let Err(e) = &result {
|
||||
|
||||
Reference in New Issue
Block a user