mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Merge pull request #1124 from Enet4/arg_enum_trailing_comma
Support trailing comma in arg_enum! fields
This commit is contained in:
commit
e0f8479e0f
2 changed files with 38 additions and 1 deletions
|
@ -345,6 +345,14 @@ macro_rules! arg_enum {
|
|||
}
|
||||
});
|
||||
};
|
||||
($(#[$($m:meta),+])+ pub enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
|
||||
arg_enum!(@impls
|
||||
($(#[$($m),+])+
|
||||
pub enum $e {
|
||||
$($v$(=$val)*),+
|
||||
}) -> ($e, $($v),+)
|
||||
);
|
||||
};
|
||||
($(#[$($m:meta),+])+ pub enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
|
||||
arg_enum!(@impls
|
||||
($(#[$($m),+])+
|
||||
|
@ -353,7 +361,14 @@ macro_rules! arg_enum {
|
|||
}) -> ($e, $($v),+)
|
||||
);
|
||||
};
|
||||
($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
|
||||
($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
|
||||
arg_enum!($(#[$($m:meta),+])+
|
||||
enum $e:ident {
|
||||
$($v:ident $(=$val:expr)*),+
|
||||
}
|
||||
);
|
||||
};
|
||||
($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
|
||||
arg_enum!(@impls
|
||||
($(#[$($m),+])+
|
||||
enum $e {
|
||||
|
@ -361,6 +376,11 @@ macro_rules! arg_enum {
|
|||
}) -> ($e, $($v),+)
|
||||
);
|
||||
};
|
||||
(pub enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
|
||||
arg_enum!(pub enum $e:ident {
|
||||
$($v:ident $(=$val:expr)*),+
|
||||
});
|
||||
};
|
||||
(pub enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
|
||||
arg_enum!(@impls
|
||||
(pub enum $e {
|
||||
|
@ -368,6 +388,11 @@ macro_rules! arg_enum {
|
|||
}) -> ($e, $($v),+)
|
||||
);
|
||||
};
|
||||
(enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => {
|
||||
arg_enum!(enum $e:ident {
|
||||
$($v:ident $(=$val:expr)*),+
|
||||
});
|
||||
};
|
||||
(enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => {
|
||||
arg_enum!(@impls
|
||||
(enum $e {
|
||||
|
|
|
@ -159,3 +159,15 @@ fn arg_enum() {
|
|||
}
|
||||
assert_eq!("Alpha".parse::<Greek>(), Ok(Greek::Alpha));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arg_enum_trailing_comma() {
|
||||
arg_enum!{
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum Greek {
|
||||
Alpha,
|
||||
Bravo,
|
||||
}
|
||||
}
|
||||
assert_eq!("Alpha".parse::<Greek>(), Ok(Greek::Alpha));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue