diff --git a/clap_derive/src/derives/clap.rs b/clap_derive/src/derives/clap.rs index 08fb5144..cca20aec 100644 --- a/clap_derive/src/derives/clap.rs +++ b/clap_derive/src/derives/clap.rs @@ -31,6 +31,17 @@ pub fn derive_clap(input: &syn::DeriveInput) -> proc_macro2::TokenStream { dummies::clap_struct(ident); gen_for_struct(ident, &fields.named, &input.attrs) } + Struct(syn::DataStruct { + fields: syn::Fields::Unit, + .. + }) => { + dummies::clap_struct(ident); + gen_for_struct( + ident, + &punctuated::Punctuated::::new(), + &input.attrs, + ) + } Enum(ref e) => { dummies::clap_enum(ident); gen_for_enum(ident, &input.attrs, e) diff --git a/clap_derive/tests/basic.rs b/clap_derive/tests/basic.rs index a3d31fbd..6091ef9a 100644 --- a/clap_derive/tests/basic.rs +++ b/clap_derive/tests/basic.rs @@ -28,3 +28,11 @@ fn basic() { Opt::parse_from(&["test", "-a24", "--arg", "42"]) ); } + +#[test] +fn unit_struct() { + #[derive(Clap, PartialEq, Debug)] + struct Opt; + + assert_eq!(Opt {}, Opt::parse_from(&["test"])); +}