From 2d94eb974f0f536883642a9547d5e5a5e5a1311a Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:21:20 +0000 Subject: [PATCH] feat: flag and config to skip notifications by jlucktay (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: flag and config to skip notifications At the end of a run, topgrade normally sends a system notification. This change adds a command-line flag and a config-file option to disable this behaviour. * fix: clippy issues Also derive Eq where PartialEq is being derived. https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq Authored-by: James Lucktaylor Approved-by: Thomas Schönauer --- Cargo.lock | 2 +- Cargo.toml | 2 +- config.example.toml | 3 +++ src/config.rs | 14 ++++++++++++++ src/main.rs | 18 +++++++++++------- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d91d01ae..dcde0ca0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1834,7 +1834,7 @@ dependencies = [ [[package]] name = "topgrade" -version = "9.0.1" +version = "9.1.0" dependencies = [ "anyhow", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 1c63663a..2a00c1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ categories = ["os"] keywords = ["upgrade", "update"] license-file = "LICENSE" repository = "https://github.com/r-darwish/topgrade" -version = "9.0.1" +version = "9.1.0" authors = ["Roey Darwish Dror "] exclude = ["doc/screenshot.gif"] edition = "2018" diff --git a/config.example.toml b/config.example.toml index 5cc7eaea..df506e86 100644 --- a/config.example.toml +++ b/config.example.toml @@ -37,6 +37,9 @@ # Cleanup temporary or old files #cleanup = true +# Skip sending a notification at the end of a run +#skip_notify = true + [git] #max_concurrency = 5 # Additional git repositories to pull diff --git a/src/config.rs b/src/config.rs index fcfdcdee..001c242a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -272,6 +272,7 @@ pub struct ConfigFile { cleanup: Option, notify_each_step: Option, accept_all_windows_updates: Option, + skip_notify: Option, bashit_branch: Option, only: Option>, composer: Option, @@ -428,6 +429,10 @@ pub struct CommandLineArgs { #[clap(short = 'k', long = "keep")] keep_at_end: bool, + /// Skip sending a notification at the end of a run + #[clap(long = "skip-notify")] + skip_notify: bool, + /// Say yes to package manager's prompt #[clap(short = 'y', long = "yes", arg_enum, multiple_values = true, min_values = 0)] yes: Option>, @@ -613,6 +618,15 @@ impl Config { self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok() } + /// Skip sending a notification at the end of a run + pub fn skip_notify(&self) -> bool { + if let Some(yes) = self.config_file.skip_notify { + return yes; + } + + self.opt.skip_notify + } + /// Whether to set the terminal title pub fn set_title(&self) -> bool { self.config_file.set_title.unwrap_or(true) diff --git a/src/main.rs b/src/main.rs index 1757cdaa..ea591742 100644 --- a/src/main.rs +++ b/src/main.rs @@ -466,13 +466,17 @@ fn run() -> Result<()> { } let failed = post_command_failed || runner.report().data().iter().any(|(_, result)| result.failed()); - terminal::notify_desktop( - format!( - "Topgrade finished {}", - if failed { "with errors" } else { "successfully" } - ), - None, - ); + + if !config.skip_notify() { + terminal::notify_desktop( + format!( + "Topgrade finished {}", + if failed { "with errors" } else { "successfully" } + ), + None, + ); + } + if failed { Err(StepFailed.into()) } else {