diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-05-03 16:01:26 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-05-03 16:02:53 -0400 |
commit | 2feed7e2e9367c935aeb669daab66a63cff2f6c0 (patch) | |
tree | 17c20ca1a762c2bb2a017506dfdc1cda30a9c25b | |
parent | fbd23df0526996a6745895e8e5f2266f88e75e7e (diff) | |
download | rbw-2feed7e2e9367c935aeb669daab66a63cff2f6c0.tar.gz rbw-2feed7e2e9367c935aeb669daab66a63cff2f6c0.zip |
add command to clear a config setting
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/bin/rbw/commands.rs | 17 | ||||
-rw-r--r-- | src/bin/rbw/main.rs | 14 | ||||
-rw-r--r-- | src/config.rs | 2 |
4 files changed, 33 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d560034..7b76d3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Multi-server support - you can now switch between multiple different bitwarden servers with `rbw config set base_url` without needing to redownload the password database each time. +* `rbw config unset` to reset configuration items back to the default ### Fixed diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index a6e98c7..a2e9f9d 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -75,6 +75,23 @@ pub fn config_set(key: &str, value: &str) -> anyhow::Result<()> { Ok(()) } +pub fn config_unset(key: &str) -> anyhow::Result<()> { + let mut config = rbw::config::Config::load() + .unwrap_or_else(|_| rbw::config::Config::new()); + match key { + "email" => config.email = None, + "base_url" => config.base_url = None, + "identity_url" => config.identity_url = None, + "lock_timeout" => { + config.lock_timeout = rbw::config::default_lock_timeout() + } + _ => return Err(anyhow::anyhow!("invalid config key: {}", key)), + } + config.save().context("failed to save config file")?; + + Ok(()) +} + pub fn login() -> anyhow::Result<()> { ensure_agent()?; crate::actions::login()?; diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs index f763fe9..e2f2e85 100644 --- a/src/bin/rbw/main.rs +++ b/src/bin/rbw/main.rs @@ -37,6 +37,15 @@ fn main() { "Value to set the configuration option to", ), ), + ) + .subcommand( + clap::SubCommand::with_name("unset") + .about("Reset a configuration option to its default") + .arg( + clap::Arg::with_name("key") + .required(true) + .help("Configuration key to unset"), + ), ), ) .subcommand( @@ -271,6 +280,11 @@ fn main() { ssmatches.value_of("value").unwrap(), ) .context("config set"), + // this unwrap is fine because key is marked .required(true) + ("unset", Some(ssmatches)) => { + commands::config_unset(ssmatches.value_of("key").unwrap()) + .context("config unset") + } _ => { eprintln!("{}", smatches.usage()); std::process::exit(1); diff --git a/src/config.rs b/src/config.rs index 7bbb928..caa27a6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,7 +12,7 @@ pub struct Config { pub lock_timeout: u64, } -fn default_lock_timeout() -> u64 { +pub fn default_lock_timeout() -> u64 { 3600 } |