rustic_rs/commands/
config.rs1use crate::{Application, RUSTIC_APP, status_err};
4
5use abscissa_core::{Command, Runnable, Shutdown};
6
7use anyhow::{Result, bail};
8
9use rustic_core::ConfigOptions;
10
11#[derive(clap::Parser, Command, Debug)]
13pub(crate) struct ConfigCmd {
14 #[clap(flatten)]
16 config_opts: ConfigOptions,
17}
18
19impl Runnable for ConfigCmd {
20 fn run(&self) {
21 if let Err(err) = self.inner_run() {
22 status_err!("{}", err);
23 RUSTIC_APP.shutdown(Shutdown::Crash);
24 };
25 }
26}
27
28impl ConfigCmd {
29 fn inner_run(&self) -> Result<()> {
30 let config = RUSTIC_APP.config();
31
32 if config.global.dry_run {
34 bail!("cannot modify config in dry-run mode!",);
35 }
36
37 let changed = config
38 .repository
39 .run_open(|mut repo| Ok(repo.apply_config(&self.config_opts)?))?;
40
41 if changed {
42 println!("saved new config");
43 } else {
44 println!("config is unchanged");
45 }
46
47 Ok(())
48 }
49}