feat: flag and config to skip notifications by jlucktay (#5)
* 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 <jlucktay+github@gmail.com> Approved-by: Thomas Schönauer <t.schoenauer@hgs-wt.at>
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1834,7 +1834,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "topgrade"
|
||||
version = "9.0.1"
|
||||
version = "9.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cfg-if",
|
||||
|
||||
@@ -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 <roey.ghost@gmail.com>"]
|
||||
exclude = ["doc/screenshot.gif"]
|
||||
edition = "2018"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -272,6 +272,7 @@ pub struct ConfigFile {
|
||||
cleanup: Option<bool>,
|
||||
notify_each_step: Option<bool>,
|
||||
accept_all_windows_updates: Option<bool>,
|
||||
skip_notify: Option<bool>,
|
||||
bashit_branch: Option<String>,
|
||||
only: Option<Vec<Step>>,
|
||||
composer: Option<Composer>,
|
||||
@@ -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<Vec<Step>>,
|
||||
@@ -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)
|
||||
|
||||
18
src/main.rs
18
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 {
|
||||
|
||||
Reference in New Issue
Block a user