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]]
|
[[package]]
|
||||||
name = "topgrade"
|
name = "topgrade"
|
||||||
version = "9.0.1"
|
version = "9.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ categories = ["os"]
|
|||||||
keywords = ["upgrade", "update"]
|
keywords = ["upgrade", "update"]
|
||||||
license-file = "LICENSE"
|
license-file = "LICENSE"
|
||||||
repository = "https://github.com/r-darwish/topgrade"
|
repository = "https://github.com/r-darwish/topgrade"
|
||||||
version = "9.0.1"
|
version = "9.1.0"
|
||||||
authors = ["Roey Darwish Dror <roey.ghost@gmail.com>"]
|
authors = ["Roey Darwish Dror <roey.ghost@gmail.com>"]
|
||||||
exclude = ["doc/screenshot.gif"]
|
exclude = ["doc/screenshot.gif"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@@ -37,6 +37,9 @@
|
|||||||
# Cleanup temporary or old files
|
# Cleanup temporary or old files
|
||||||
#cleanup = true
|
#cleanup = true
|
||||||
|
|
||||||
|
# Skip sending a notification at the end of a run
|
||||||
|
#skip_notify = true
|
||||||
|
|
||||||
[git]
|
[git]
|
||||||
#max_concurrency = 5
|
#max_concurrency = 5
|
||||||
# Additional git repositories to pull
|
# Additional git repositories to pull
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ pub struct ConfigFile {
|
|||||||
cleanup: Option<bool>,
|
cleanup: Option<bool>,
|
||||||
notify_each_step: Option<bool>,
|
notify_each_step: Option<bool>,
|
||||||
accept_all_windows_updates: Option<bool>,
|
accept_all_windows_updates: Option<bool>,
|
||||||
|
skip_notify: Option<bool>,
|
||||||
bashit_branch: Option<String>,
|
bashit_branch: Option<String>,
|
||||||
only: Option<Vec<Step>>,
|
only: Option<Vec<Step>>,
|
||||||
composer: Option<Composer>,
|
composer: Option<Composer>,
|
||||||
@@ -428,6 +429,10 @@ pub struct CommandLineArgs {
|
|||||||
#[clap(short = 'k', long = "keep")]
|
#[clap(short = 'k', long = "keep")]
|
||||||
keep_at_end: bool,
|
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
|
/// Say yes to package manager's prompt
|
||||||
#[clap(short = 'y', long = "yes", arg_enum, multiple_values = true, min_values = 0)]
|
#[clap(short = 'y', long = "yes", arg_enum, multiple_values = true, min_values = 0)]
|
||||||
yes: Option<Vec<Step>>,
|
yes: Option<Vec<Step>>,
|
||||||
@@ -613,6 +618,15 @@ impl Config {
|
|||||||
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()
|
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
|
/// Whether to set the terminal title
|
||||||
pub fn set_title(&self) -> bool {
|
pub fn set_title(&self) -> bool {
|
||||||
self.config_file.set_title.unwrap_or(true)
|
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());
|
let failed = post_command_failed || runner.report().data().iter().any(|(_, result)| result.failed());
|
||||||
terminal::notify_desktop(
|
|
||||||
format!(
|
if !config.skip_notify() {
|
||||||
"Topgrade finished {}",
|
terminal::notify_desktop(
|
||||||
if failed { "with errors" } else { "successfully" }
|
format!(
|
||||||
),
|
"Topgrade finished {}",
|
||||||
None,
|
if failed { "with errors" } else { "successfully" }
|
||||||
);
|
),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if failed {
|
if failed {
|
||||||
Err(StepFailed.into())
|
Err(StepFailed.into())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user