From 04b4262cdf4bbb4e2698d8ce51a261bf294a2da3 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 5 Sep 2020 13:18:41 +0200 Subject: 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 --- src/args.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/args.rs') 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, #[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(deserializer: D) -> Result + 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, [ -- cgit v1.2.1