Skip to content

Commit 8561410

Browse files
committed
make json a global option
1 parent aaedf27 commit 8561410

7 files changed

Lines changed: 17 additions & 29 deletions

File tree

config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ If you want to contribute your own configuration, please
6060
| dry-run | If true, performs a dry run without making any changes. | false | | RUSTIC_DRY_RUN |
6161
| log-level | Logging level. Possible values: "off", "error", "warn", "info", "debug", "trace". | "info" | | RUSTIC_LOG_LEVEL |
6262
| log-file | Path to the log file. | No log file | "/log/rustic.log" | RUSTIC_LOG_FILE |
63+
| json | If true, returns output of the command as json. | false | | RUSTIC_JSON |
6364
| no-progress | If true, disables progress indicators. | false | | RUSTIC_NO_PROGRESS |
6465
| progress-interval | The interval at which progress indicators are shown. | "100ms" | "1m" | RUSTIC_PROGRESS_INTERVAL |
6566
| use-profile | An array of profiles to use. Allows to recursely use other profiles. | Empty array | | RUSTIC_USE_PROFILE |
@@ -133,7 +134,6 @@ can be overwritten in the source-specifc configuration, see below.
133134
| ignore-ctime | If true, ignore file change time (ctime). | false | |
134135
| ignore-inode | If true, ignore file inode for the backup. | false | |
135136
| init | If true, initialize repository if it doesn't exist, yet. | false | |
136-
| json | If true, returns output of the command as json. | false | |
137137
| label | Set label fot the snapshot. | Not set | |
138138
| no-require-git | (with git-ignore:) Apply .git-ignore files even if they are not in a git repository. | false | |
139139
| no-scan | Don't scan the backup source for its size (disables ETA). | false | |

src/commands/backup.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ pub struct BackupCmd {
5353
/// Don't scan the backup source for its size - this disables ETA estimation for backup.
5454
#[clap(long)]
5555
#[merge(strategy = merge::bool::overwrite_false)]
56-
pub no_scan: bool,
57-
58-
/// Output generated snapshot in json format
59-
#[clap(long)]
60-
#[merge(strategy = merge::bool::overwrite_false)]
61-
json: bool,
56+
no_scan: bool,
6257

6358
/// Don't show any output
6459
#[clap(long, conflicts_with = "json")]
@@ -228,7 +223,7 @@ impl BackupCmd {
228223
.dry_run(config.global.dry_run);
229224
let snap = repo.backup(&backup_opts, &source, opts.snap_opts.to_snapshot()?)?;
230225

231-
if opts.json {
226+
if config.global.json {
232227
let mut stdout = std::io::stdout();
233228
serde_json::to_writer_pretty(&mut stdout, &snap)?;
234229
} else if !opts.quiet {

src/commands/forget.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ pub(super) struct ForgetCmd {
2626
#[clap(value_name = "ID")]
2727
ids: Vec<String>,
2828

29-
/// Show infos in json format
30-
#[clap(long)]
31-
json: bool,
32-
3329
/// Don't show any output
3430
#[clap(long, conflicts_with = "json")]
3531
quiet: bool,
@@ -123,7 +119,7 @@ impl ForgetCmd {
123119
ForgetGroups(vec![item])
124120
};
125121

126-
if self.json {
122+
if config.global.json {
127123
let mut stdout = std::io::stdout();
128124
serde_json::to_writer_pretty(&mut stdout, &groups)?;
129125
} else if !self.quiet {
@@ -132,7 +128,11 @@ impl ForgetCmd {
132128

133129
let forget_snaps = groups.into_forget_ids();
134130

135-
match (forget_snaps.is_empty(), config.global.dry_run, self.json) {
131+
match (
132+
forget_snaps.is_empty(),
133+
config.global.dry_run,
134+
config.global.json,
135+
) {
136136
(true, _, false) => println!("nothing to remove"),
137137
(false, true, false) => {
138138
println!("would have removed the following snapshots:\n {forget_snaps:?}");

src/commands/merge.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ pub(super) struct MergeCmd {
1616
#[clap(value_name = "ID")]
1717
ids: Vec<String>,
1818

19-
/// Output generated snapshot in json format
20-
#[clap(long)]
21-
json: bool,
22-
2319
/// Remove input snapshots after merging
2420
#[clap(long)]
2521
delete: bool,
@@ -53,7 +49,7 @@ impl MergeCmd {
5349

5450
let snap = repo.merge_snapshots(&snapshots, &last_modified_node, snap)?;
5551

56-
if self.json {
52+
if config.global.json {
5753
let mut stdout = std::io::stdout();
5854
serde_json::to_writer_pretty(&mut stdout, &snap)?;
5955
}

src/commands/repoinfo.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ pub(crate) struct RepoInfoCmd {
2222
/// Only scan index
2323
#[clap(long)]
2424
only_index: bool,
25-
26-
/// Show infos in json format
27-
#[clap(long)]
28-
json: bool,
2925
}
3026

3127
impl Runnable for RepoInfoCmd {
@@ -66,7 +62,7 @@ impl RepoInfoCmd {
6662
.transpose()?,
6763
};
6864

69-
if self.json {
65+
if config.global.json {
7066
let mut stdout = std::io::stdout();
7167
serde_json::to_writer_pretty(&mut stdout, &infos)?;
7268
return Ok(());

src/commands/snapshots.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ pub(crate) struct SnapshotCmd {
3737
#[arg(long)]
3838
long: bool,
3939

40-
/// Show snapshots in json format
41-
#[clap(long, conflicts_with = "long")]
42-
json: bool,
43-
4440
/// Show all snapshots instead of summarizing identical follow-up snapshots
4541
#[clap(long, conflicts_with_all = &["long", "json"])]
4642
all: bool,
@@ -64,7 +60,7 @@ impl SnapshotCmd {
6460
config.snapshot_filter.matches(sn)
6561
})?;
6662

67-
if self.json {
63+
if config.global.json {
6864
let mut stdout = std::io::stdout();
6965
serde_json::to_writer_pretty(&mut stdout, &groups)?;
7066
return Ok(());

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ pub struct GlobalOptions {
158158
#[clap(long, global = true, env = "RUSTIC_LOG_FILE", value_name = "LOGFILE")]
159159
pub log_file: Option<PathBuf>,
160160

161+
/// Output in JSON format
162+
#[clap(long, global = true, env = "RUSTIC_JSON")]
163+
#[merge(strategy = merge::bool::overwrite_false)]
164+
pub json: bool,
165+
161166
/// Settings to customize progress bars
162167
#[clap(flatten)]
163168
#[serde(flatten)]

0 commit comments

Comments
 (0)