diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-09-05 13:18:41 +0200 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2020-09-05 13:18:41 +0200 |
commit | 04b4262cdf4bbb4e2698d8ce51a261bf294a2da3 (patch) | |
tree | 9de5eda786b20ac1b6350144499ce08fd4baa6c9 /src/args.rs | |
parent | 9dca5be8b182773a7b7eb23b47296d403540ead4 (diff) | |
download | nitrocli-04b4262cdf4bbb4e2698d8ce51a261bf294a2da3.tar.gz nitrocli-04b4262cdf4bbb4e2698d8ce51a261bf294a2da3.tar.bz2 |
Add --output-format argument
This patch adds the --output-format argument that makes it possible to
select a format for the data that nitrocli prints to stdout. Currently,
the only supported format is text output, i. e. a human-readable
representation.
TODO: man page, changelog
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs index f54025e..758af8c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -16,6 +16,9 @@ pub struct Args { /// Disables the cache for all secrets. #[structopt(long, global = true)] pub no_cache: bool, + /// Selects the output format. + #[structopt(long, global = true, possible_values = &OutputFormat::all_str())] + pub output_format: Option<OutputFormat>, #[structopt(subcommand)] pub cmd: Command, } @@ -68,6 +71,26 @@ impl<'de> serde::Deserialize<'de> for DeviceModel { } } +Enum! { + /// The format for the nitrocli output. + OutputFormat, [ + Text => "text", + ] +} + +impl<'de> serde::Deserialize<'de> for OutputFormat { + fn deserialize<D>(deserializer: D) -> Result<OutputFormat, D::Error> + where + D: serde::Deserializer<'de>, + { + use serde::de::Error as _; + use std::str::FromStr as _; + + let s = String::deserialize(deserializer)?; + OutputFormat::from_str(&s).map_err(D::Error::custom) + } +} + Command! { /// A top-level command for nitrocli. Command, [ |