diff --git a/src/commands/backup.rs b/src/commands/backup.rs index 9449b0174..9a6190119 100644 --- a/src/commands/backup.rs +++ b/src/commands/backup.rs @@ -53,12 +53,7 @@ pub struct BackupCmd { /// Don't scan the backup source for its size - this disables ETA estimation for backup. #[clap(long)] #[merge(strategy = merge::bool::overwrite_false)] - pub no_scan: bool, - - /// Output generated snapshot in json format - #[clap(long)] - #[merge(strategy = merge::bool::overwrite_false)] - json: bool, + no_scan: bool, /// Don't show any output #[clap(long, conflicts_with = "json")] @@ -228,7 +223,7 @@ impl BackupCmd { .dry_run(config.global.dry_run); let snap = repo.backup(&backup_opts, &source, opts.snap_opts.to_snapshot()?)?; - if opts.json { + if config.global.json { let mut stdout = std::io::stdout(); serde_json::to_writer_pretty(&mut stdout, &snap)?; } else if !opts.quiet { diff --git a/src/commands/forget.rs b/src/commands/forget.rs index 6ce30ee0a..0735d1dab 100644 --- a/src/commands/forget.rs +++ b/src/commands/forget.rs @@ -26,10 +26,6 @@ pub(super) struct ForgetCmd { #[clap(value_name = "ID")] ids: Vec, - /// Show infos in json format - #[clap(long)] - json: bool, - /// Don't show any output #[clap(long, conflicts_with = "json")] quiet: bool, @@ -123,7 +119,7 @@ impl ForgetCmd { ForgetGroups(vec![item]) }; - if self.json { + if config.global.json { let mut stdout = std::io::stdout(); serde_json::to_writer_pretty(&mut stdout, &groups)?; } else if !self.quiet { @@ -132,7 +128,11 @@ impl ForgetCmd { let forget_snaps = groups.into_forget_ids(); - match (forget_snaps.is_empty(), config.global.dry_run, self.json) { + match ( + forget_snaps.is_empty(), + config.global.dry_run, + config.global.json, + ) { (true, _, false) => println!("nothing to remove"), (false, true, false) => { println!("would have removed the following snapshots:\n {forget_snaps:?}"); diff --git a/src/commands/merge.rs b/src/commands/merge.rs index aa102f349..6485d3625 100644 --- a/src/commands/merge.rs +++ b/src/commands/merge.rs @@ -16,10 +16,6 @@ pub(super) struct MergeCmd { #[clap(value_name = "ID")] ids: Vec, - /// Output generated snapshot in json format - #[clap(long)] - json: bool, - /// Remove input snapshots after merging #[clap(long)] delete: bool, @@ -53,7 +49,7 @@ impl MergeCmd { let snap = repo.merge_snapshots(&snapshots, &last_modified_node, snap)?; - if self.json { + if config.global.json { let mut stdout = std::io::stdout(); serde_json::to_writer_pretty(&mut stdout, &snap)?; } diff --git a/src/commands/repoinfo.rs b/src/commands/repoinfo.rs index 16750f6cf..962267880 100644 --- a/src/commands/repoinfo.rs +++ b/src/commands/repoinfo.rs @@ -22,10 +22,6 @@ pub(crate) struct RepoInfoCmd { /// Only scan index #[clap(long)] only_index: bool, - - /// Show infos in json format - #[clap(long)] - json: bool, } impl Runnable for RepoInfoCmd { @@ -66,7 +62,7 @@ impl RepoInfoCmd { .transpose()?, }; - if self.json { + if config.global.json { let mut stdout = std::io::stdout(); serde_json::to_writer_pretty(&mut stdout, &infos)?; return Ok(()); diff --git a/src/commands/snapshots.rs b/src/commands/snapshots.rs index 2b4e0821f..b137ea321 100644 --- a/src/commands/snapshots.rs +++ b/src/commands/snapshots.rs @@ -37,10 +37,6 @@ pub(crate) struct SnapshotCmd { #[arg(long)] long: bool, - /// Show snapshots in json format - #[clap(long, conflicts_with = "long")] - json: bool, - /// Show all snapshots instead of summarizing identical follow-up snapshots #[clap(long, conflicts_with_all = &["long", "json"])] all: bool, @@ -64,7 +60,7 @@ impl SnapshotCmd { config.snapshot_filter.matches(sn) })?; - if self.json { + if config.global.json { let mut stdout = std::io::stdout(); serde_json::to_writer_pretty(&mut stdout, &groups)?; return Ok(()); diff --git a/src/config.rs b/src/config.rs index 3a6d3757c..2ffeb1904 100644 --- a/src/config.rs +++ b/src/config.rs @@ -158,6 +158,11 @@ pub struct GlobalOptions { #[clap(long, global = true, env = "RUSTIC_LOG_FILE", value_name = "LOGFILE")] pub log_file: Option, + /// Output in JSON format + #[clap(long, global = true, env = "RUSTIC_JSON")] + #[merge(strategy = merge::bool::overwrite_false)] + pub json: bool, + /// Settings to customize progress bars #[clap(flatten)] #[serde(flatten)]