diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-01-23 10:54:09 +0100 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2021-01-10 10:03:09 -0800 |
commit | 9d3c50ca3f9ff0bf12b1b25344959ed333ffbdee (patch) | |
tree | e1887917dc1eb94a23642ebe26b2f6c02b705188 /src/args.rs | |
parent | 887f3cb9aab12b390ae9efe09c1ff7f972e51c35 (diff) | |
download | nitrocli-9d3c50ca3f9ff0bf12b1b25344959ed333ffbdee.tar.gz nitrocli-9d3c50ca3f9ff0bf12b1b25344959ed333ffbdee.tar.bz2 |
Implement configuration handling
This patch implements basic configuration handling that reads a
configuration file and stores the parsed data in the ExecCtx and RunCtx
structs. It supports three configuration items:
- model (previously only --model)
- no_cache (previously only NITROCLI_NO_CACHE)
- verbosity (previously only --verbose)
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/args.rs b/src/args.rs index 0f548e4..7f2dc31 100644 --- a/src/args.rs +++ b/src/args.rs @@ -18,7 +18,7 @@ // ************************************************************************* /// Provides access to a Nitrokey device -#[derive(structopt::StructOpt)] +#[derive(Debug, structopt::StructOpt)] #[structopt(name = "nitrocli")] pub struct Args { /// Increases the log level (can be supplied multiple times) @@ -57,6 +57,19 @@ impl From<DeviceModel> for nitrokey::Model { } } +impl<'de> serde::Deserialize<'de> for DeviceModel { + fn deserialize<D>(deserializer: D) -> Result<DeviceModel, D::Error> + where + D: serde::Deserializer<'de>, + { + use serde::de::Error as _; + use std::str::FromStr as _; + + let s = String::deserialize(deserializer)?; + DeviceModel::from_str(&s).map_err(D::Error::custom) + } +} + Command! { /// A top-level command for nitrocli. Command, [ |