summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-12-23 09:44:31 +0200
committerLars Wirzenius <liw@liw.fi>2020-12-23 10:17:17 +0200
commit15ce048ca21ad517e27ab598d861ae07f817067d (patch)
tree01857ffa023c770164a9cc07d1024ed388150864 /src/bin
parentd6584921d8bb77fd4de8b6997848599cb9d73e01 (diff)
downloadobnam2-15ce048ca21ad517e27ab598d861ae07f817067d.tar.gz
feat! add a global --config option
This breaks all invocations of the Obnam client, as the option needs to come before the subcommand name. The benefit of this breakage is simpler, less repetitive code.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/obnam.rs35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs
index 1394b6c..bc636dc 100644
--- a/src/bin/obnam.rs
+++ b/src/bin/obnam.rs
@@ -1,4 +1,5 @@
use log::{debug, info};
+use obnam::client::ClientConfig;
use obnam::cmd::{backup, list, restore};
use std::path::PathBuf;
use structopt::StructOpt;
@@ -9,32 +10,34 @@ fn main() -> anyhow::Result<()> {
pretty_env_logger::init();
let opt = Opt::from_args();
+ let config = ClientConfig::read_config(&opt.config)?;
+
info!("obnam starts");
debug!("opt: {:?}", opt);
- match opt {
- Opt::Backup { config } => backup(&config, BUFFER_SIZE)?,
- Opt::List { config } => list(&config)?,
- Opt::Restore { config, gen_id, to } => restore(&config, &gen_id, &to)?,
+ match opt.cmd {
+ Command::Backup => backup(&config, BUFFER_SIZE)?,
+ Command::List => list(&config)?,
+ Command::Restore { gen_id, to } => restore(&config, &gen_id, &to)?,
}
Ok(())
}
#[derive(Debug, StructOpt)]
#[structopt(name = "obnam-backup", about = "Simplistic backup client")]
-enum Opt {
- Backup {
- #[structopt(parse(from_os_str))]
- config: PathBuf,
- },
- List {
- #[structopt(parse(from_os_str))]
- config: PathBuf,
- },
- Restore {
- #[structopt(parse(from_os_str))]
- config: PathBuf,
+struct Opt {
+ #[structopt(long, short, parse(from_os_str))]
+ config: PathBuf,
+
+ #[structopt(subcommand)]
+ cmd: Command,
+}
+#[derive(Debug, StructOpt)]
+enum Command {
+ Backup,
+ List,
+ Restore {
#[structopt()]
gen_id: String,