From 984f5fadd1bfcd0184af8bddc4973acfe8affb64 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Tue, 15 Jan 2019 15:26:56 -0800 Subject: Auto-generate help text for enum-backed optional arguments This change continues the effort of auto-generating more of the help text content by extending the logic to optional arguments. We make use of the fmt_enum macro to format the description of the argument with the available variants (as well as the default, if any) interpolated. --- nitrocli/src/pinentry.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'nitrocli/src/pinentry.rs') diff --git a/nitrocli/src/pinentry.rs b/nitrocli/src/pinentry.rs index 1eecdd0..d6f000c 100644 --- a/nitrocli/src/pinentry.rs +++ b/nitrocli/src/pinentry.rs @@ -26,25 +26,10 @@ use crate::error::Error; /// /// The available PIN types correspond to the PIN types used by the Nitrokey devices: user and /// admin. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum PinType { - /// The admin PIN. - Admin, - /// The user PIN. - User, -} - -impl str::FromStr for PinType { - type Err = (); - - fn from_str(s: &str) -> Result { - match s { - "admin" => Ok(PinType::Admin), - "user" => Ok(PinType::User), - _ => Err(()), - } - } -} +Enum! {PinType, [ + Admin => "admin", + User => "user" +]} #[derive(Debug)] pub struct PinEntry { -- cgit v1.2.1