summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-05-27 08:16:27 -0700
committerDaniel Mueller <deso@posteo.net>2019-05-27 08:16:27 -0700
commitc01bbbf186cd88f9e1b3c3eda0459635bed209b4 (patch)
treed161ffd8fc36dc18ba99ff157241c6191d89c9ff
parentb637d5284c6117da3bfeb471da7c62e53a632621 (diff)
downloadnitrocli-c01bbbf186cd88f9e1b3c3eda0459635bed209b4.tar.gz
nitrocli-c01bbbf186cd88f9e1b3c3eda0459635bed209b4.tar.bz2
Require trailing comma in Enum macro's input
The input to the Enum macro is supposed to resemble the definition of an enum in Rust code. When manually defining an enum (or a struct for that matter), we typically terminate all branches with a comma, and don't just omit that on the last line. To mirror this behavior, this change adjusts the Enum macro to accept (and in fact, require) a comma-terminated last line as well, as opposed to not accepting it as had been the case so far.
-rw-r--r--nitrocli/src/arg_util.rs8
-rw-r--r--nitrocli/src/args.rs22
-rw-r--r--nitrocli/src/pinentry.rs2
3 files changed, 16 insertions, 16 deletions
diff --git a/nitrocli/src/arg_util.rs b/nitrocli/src/arg_util.rs
index 2996060..e2e7b1d 100644
--- a/nitrocli/src/arg_util.rs
+++ b/nitrocli/src/arg_util.rs
@@ -29,9 +29,9 @@ macro_rules! count {
// TODO: Right now we hard code the derives we create. We may want to
// make this set configurable.
macro_rules! Enum {
- ( $name:ident, [ $( $var:ident => ($str:expr, $exec:expr) ), *] ) => {
+ ( $name:ident, [ $( $var:ident => ($str:expr, $exec:expr), ) *] ) => {
Enum! {$name, [
- $( $var => $str ),*
+ $( $var => $str, )*
]}
#[allow(unused_qualifications)]
@@ -49,7 +49,7 @@ macro_rules! Enum {
}
}
};
- ( $name:ident, [ $( $var:ident => $str:expr ), *] ) => {
+ ( $name:ident, [ $( $var:ident => $str:expr, ) *] ) => {
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum $name {
$(
@@ -138,7 +138,7 @@ mod tests {
Enum! {Command, [
Var1 => "var1",
Var2 => "2",
- Var3 => "crazy"
+ Var3 => "crazy",
]}
#[test]
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index 7e4f839..82e9c2a 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/src/args.rs
@@ -104,7 +104,7 @@ impl<'io> Stdio for ExecCtx<'io> {
#[allow(unused_doc_comments)]
Enum! {DeviceModel, [
Pro => "pro",
- Storage => "storage"
+ Storage => "storage",
]}
impl From<DeviceModel> for nitrokey::Model {
@@ -126,12 +126,12 @@ Enum! {Command, [
Pws => ("pws", pws),
Reset => ("reset", reset),
Status => ("status", status),
- Storage => ("storage", storage)
+ Storage => ("storage", storage),
]}
Enum! {ConfigCommand, [
Get => ("get", config_get),
- Set => ("set", config_set)
+ Set => ("set", config_set),
]}
#[derive(Clone, Copy, Debug)]
@@ -173,17 +173,17 @@ Enum! {OtpCommand, [
Clear => ("clear", otp_clear),
Get => ("get", otp_get),
Set => ("set", otp_set),
- Status => ("status", otp_status)
+ Status => ("status", otp_status),
]}
Enum! {OtpAlgorithm, [
Hotp => "hotp",
- Totp => "totp"
+ Totp => "totp",
]}
Enum! {OtpMode, [
SixDigits => "6",
- EightDigits => "8"
+ EightDigits => "8",
]}
impl From<OtpMode> for nitrokey::OtpMode {
@@ -198,20 +198,20 @@ impl From<OtpMode> for nitrokey::OtpMode {
Enum! {OtpSecretFormat, [
Ascii => "ascii",
Base32 => "base32",
- Hex => "hex"
+ Hex => "hex",
]}
Enum! {PinCommand, [
Clear => ("clear", pin_clear),
Set => ("set", pin_set),
- Unblock => ("unblock", pin_unblock)
+ Unblock => ("unblock", pin_unblock),
]}
Enum! {PwsCommand, [
Clear => ("clear", pws_clear),
Get => ("get", pws_get),
Set => ("set", pws_set),
- Status => ("status", pws_status)
+ Status => ("status", pws_status),
]}
fn parse(
@@ -249,7 +249,7 @@ Enum! {StorageCommand, [
Close => ("close", storage_close),
Hidden => ("hidden", storage_hidden),
Open => ("open", storage_open),
- Status => ("status", storage_status)
+ Status => ("status", storage_status),
]}
/// Execute a storage subcommand.
@@ -306,7 +306,7 @@ fn storage_status(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
Enum! {HiddenCommand, [
Close => ("close", storage_hidden_close),
Create => ("create", storage_hidden_create),
- Open => ("open", storage_hidden_open)
+ Open => ("open", storage_hidden_open),
]}
/// Execute a storage hidden subcommand.
diff --git a/nitrocli/src/pinentry.rs b/nitrocli/src/pinentry.rs
index 8bab65e..7bba6b9 100644
--- a/nitrocli/src/pinentry.rs
+++ b/nitrocli/src/pinentry.rs
@@ -33,7 +33,7 @@ type CowStr = borrow::Cow<'static, str>;
#[allow(unused_doc_comments)]
Enum! {PinType, [
Admin => "admin",
- User => "user"
+ User => "user",
]}
/// A trait representing a secret to be entered by the user.