From dbbc88e568f2fd99a01d9e3fae32b7c4e5980b19 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 7 Jan 2020 15:29:44 +0000 Subject: Remove str argument from Command! macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we no longer have to implement the Display and AsRef traits for the enums generated with the Command! macro, we don’t have to set a string representation either. So we can drop this argument from the Command! macro. --- src/arg_util.rs | 2 +- src/args.rs | 58 ++++++++++++++++++++++++++++----------------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/arg_util.rs b/src/arg_util.rs index 52d1020..2f04ccd 100644 --- a/src/arg_util.rs +++ b/src/arg_util.rs @@ -25,7 +25,7 @@ macro_rules! count { } macro_rules! Command { - ( $name:ident, [ $( $var:ident($inner:ident) => ($str:expr, $exec:expr), ) *] ) => { + ( $name:ident, [ $( $var:ident($inner:ident) => $exec:expr, ) *] ) => { #[derive(Debug, PartialEq, structopt::StructOpt)] pub enum $name { $( diff --git a/src/args.rs b/src/args.rs index 82140f3..305e433 100644 --- a/src/args.rs +++ b/src/args.rs @@ -111,16 +111,16 @@ impl From for nitrokey::Model { /// A top-level command for nitrocli. #[allow(unused_doc_comments)] Command! {Command, [ - Config(ConfigArgs) => ("config", config), - Encrypted(EncryptedArgs) => ("encrypted", encrypted), - Hidden(HiddenArgs) => ("hidden", hidden), - Lock(LockArgs) => ("lock", lock), - Otp(OtpArgs) => ("otp", otp), - Pin(PinArgs) => ("pin", pin), - Pws(PwsArgs) => ("pws", pws), - Reset(ResetArgs) => ("reset", reset), - Status(StatusArgs) => ("status", status), - Unencrypted(UnencryptedArgs) => ("unencrypted", unencrypted), + Config(ConfigArgs) => config, + Encrypted(EncryptedArgs) => encrypted, + Hidden(HiddenArgs) => hidden, + Lock(LockArgs) => lock, + Otp(OtpArgs) => otp, + Pin(PinArgs) => pin, + Pws(PwsArgs) => pws, + Reset(ResetArgs) => reset, + Status(StatusArgs) => status, + Unencrypted(UnencryptedArgs) => unencrypted, ]} /// Reads or writes the device configuration @@ -374,8 +374,8 @@ pub struct UnencryptedSetArgs { } Command! {ConfigCommand, [ - Get(ConfigGetArgs) => ("get", config_get), - Set(ConfigSetArgs) => ("set", config_set), + Get(ConfigGetArgs) => config_get, + Set(ConfigSetArgs) => config_set, ]} #[derive(Clone, Copy, Debug)] @@ -414,10 +414,10 @@ impl ConfigOption { } Command! {OtpCommand, [ - Clear(OtpClearArgs) => ("clear", otp_clear), - Get(OtpGetArgs) => ("get", otp_get), - Set(OtpSetArgs) => ("set", otp_set), - Status(OtpStatusArgs) => ("status", otp_status), + Clear(OtpClearArgs) => otp_clear, + Get(OtpGetArgs) => otp_get, + Set(OtpSetArgs) => otp_set, + Status(OtpStatusArgs) => otp_status, ]} Enum! {OtpAlgorithm, [ @@ -446,16 +446,16 @@ Enum! {OtpSecretFormat, [ ]} Command! {PinCommand, [ - Clear(PinClearArgs) => ("clear", pin_clear), - Set(PinSetArgs) => ("set", pin_set), - Unblock(PinUnblockArgs) => ("unblock", pin_unblock), + Clear(PinClearArgs) => pin_clear, + Set(PinSetArgs) => pin_set, + Unblock(PinUnblockArgs) => pin_unblock, ]} Command! {PwsCommand, [ - Clear(PwsClearArgs) => ("clear", pws_clear), - Get(PwsGetArgs) => ("get", pws_get), - Set(PwsSetArgs) => ("set", pws_set), - Status(PwsStatusArgs) => ("status", pws_status), + Clear(PwsClearArgs) => pws_clear, + Get(PwsGetArgs) => pws_get, + Set(PwsSetArgs) => pws_set, + Status(PwsStatusArgs) => pws_status, ]} /// Inquire the status of the Nitrokey. @@ -469,7 +469,7 @@ fn reset(ctx: &mut ExecCtx<'_>, _args: ResetArgs) -> Result<()> { } Command! {UnencryptedCommand, [ - Set(UnencryptedSetArgs) => ("set", unencrypted_set), + Set(UnencryptedSetArgs) => unencrypted_set, ]} Enum! {UnencryptedVolumeMode, [ @@ -488,8 +488,8 @@ fn unencrypted_set(ctx: &mut ExecCtx<'_>, args: UnencryptedSetArgs) -> Result<() } Command! {EncryptedCommand, [ - Close(EncryptedCloseArgs) => ("close", encrypted_close), - Open(EncryptedOpenArgs) => ("open", encrypted_open), + Close(EncryptedCloseArgs) => encrypted_close, + Open(EncryptedOpenArgs) => encrypted_open, ]} /// Execute an encrypted subcommand. @@ -508,9 +508,9 @@ fn encrypted_close(ctx: &mut ExecCtx<'_>, _args: EncryptedCloseArgs) -> Result<( } Command! {HiddenCommand, [ - Close(HiddenCloseArgs) => ("close", hidden_close), - Create(HiddenCreateArgs) => ("create", hidden_create), - Open(HiddenOpenArgs) => ("open", hidden_open), + Close(HiddenCloseArgs) => hidden_close, + Create(HiddenCreateArgs) => hidden_create, + Open(HiddenOpenArgs) => hidden_open, ]} /// Execute a hidden subcommand. -- cgit v1.2.1