From 6be66131cb6f76c1d8120847bb462c4abd5d5077 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 8 Jan 2020 11:59:08 +0000 Subject: Remove empty Args structs for simple (sub-)commands Since we updated the Command! macro to also allow enum variants without fields, we no longer need the empty *Args structs for commands or subcommands without arguments or options. --- src/args.rs | 50 ++++++++++---------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index fb734b9..ec35f06 100644 --- a/src/args.rs +++ b/src/args.rs @@ -118,7 +118,7 @@ Command! {Command, [ /// Interacts with the device's hidden volume Hidden(HiddenArgs) => |ctx, args: HiddenArgs| args.subcmd.execute(ctx), /// Locks the connected Nitrokey device - Lock(LockArgs) => |ctx, _| commands::lock(ctx), + Lock => commands::lock, /// Accesses one-time passwords Otp(OtpArgs) => |ctx, args: OtpArgs| args.subcmd.execute(ctx), /// Manages the Nitrokey PINs @@ -126,9 +126,9 @@ Command! {Command, [ /// Accesses the password safe Pws(PwsArgs) => |ctx, args: PwsArgs| args.subcmd.execute(ctx), /// Performs a factory reset - Reset(ResetArgs) => |ctx, _| commands::reset(ctx), + Reset => commands::reset, /// Prints the status of the connected Nitrokey device - Status(StatusArgs) => |ctx, _| commands::status(ctx), + Status => commands::status, /// Interacts with the device's unencrypted volume Unencrypted(UnencryptedArgs) => |ctx, args: UnencryptedArgs| args.subcmd.execute(ctx), ]} @@ -141,14 +141,11 @@ pub struct ConfigArgs { Command! {ConfigCommand, [ /// Prints the Nitrokey configuration - Get(ConfigGetArgs) => |ctx, _| commands::config_get(ctx), + Get => commands::config_get, /// Changes the Nitrokey configuration Set(ConfigSetArgs) => config_set, ]} -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct ConfigGetArgs {} - #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct ConfigSetArgs { /// Sets the numlock option to the given HOTP slot @@ -234,17 +231,11 @@ pub struct EncryptedArgs { Command! {EncryptedCommand, [ /// Closes the encrypted volume on a Nitrokey Storage - Close(EncryptedCloseArgs) => |ctx, _| commands::encrypted_close(ctx), + Close => commands::encrypted_close, /// Opens the encrypted volume on a Nitrokey Storage - Open(EncryptedOpenArgs) => |ctx, _| commands::encrypted_open(ctx), + Open => commands::encrypted_open, ]} -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct EncryptedCloseArgs {} - -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct EncryptedOpenArgs {} - #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct HiddenArgs { #[structopt(subcommand)] @@ -253,18 +244,15 @@ pub struct HiddenArgs { Command! {HiddenCommand, [ /// Closes the hidden volume on a Nitrokey Storage - Close(HiddenCloseArgs) => |ctx, _| commands::hidden_close(ctx), + Close => commands::hidden_close, /// Creates a hidden volume on a Nitrokey Storage Create(HiddenCreateArgs) => |ctx, args: HiddenCreateArgs| { commands::hidden_create(ctx, args.slot, args.start, args.end) }, /// Opens the hidden volume on a Nitrokey Storage - Open(HiddenOpenArgs) => |ctx, _| commands::hidden_open(ctx), + Open => commands::hidden_open, ]} -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct HiddenCloseArgs {} - #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct HiddenCreateArgs { /// The hidden volume slot to use @@ -275,12 +263,6 @@ pub struct HiddenCreateArgs { end: u8, } -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct HiddenOpenArgs {} - -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct LockArgs {} - #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct OtpArgs { #[structopt(subcommand)] @@ -408,16 +390,13 @@ pub struct PinArgs { Command! {PinCommand, [ /// Clears the cached PINs - Clear(PinClearArgs) => |ctx, _| commands::pin_clear(ctx), + Clear => commands::pin_clear, /// Changes a PIN Set(PinSetArgs) => |ctx, args: PinSetArgs| commands::pin_set(ctx, args.pintype), /// Unblocks and resets the user PIN - Unblock(PinUnblockArgs) => |ctx, _| commands::pin_unblock(ctx), + Unblock => commands::pin_unblock, ]} -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct PinClearArgs {} - #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct PinSetArgs { /// The PIN type to change @@ -425,9 +404,6 @@ pub struct PinSetArgs { pintype: pinentry::PinType, } -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct PinUnblockArgs {} - #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct PwsArgs { #[structopt(subcommand)] @@ -492,12 +468,6 @@ pub struct PwsStatusArgs { all: bool, } -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct ResetArgs {} - -#[derive(Debug, PartialEq, structopt::StructOpt)] -pub struct StatusArgs {} - #[derive(Debug, PartialEq, structopt::StructOpt)] pub struct UnencryptedArgs { #[structopt(subcommand)] -- cgit v1.2.3