Skip to content

Commit

Permalink
Merge pull request #2653 from patrick-gu/master
Browse files Browse the repository at this point in the history
Make `multiple_values` `false` with derived `Option<Option<...>>`
  • Loading branch information
pksunkara committed Aug 2, 2021
2 parents 4bec66d + eca8ba6 commit 286fda0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clap_derive/src/derives/args.rs
Expand Up @@ -264,9 +264,9 @@ pub fn gen_augment(
Ty::OptionOption => quote_spanned! { ty.span()=>
.takes_value(true)
#value_name
.multiple_values(false)
.min_values(0)
.max_values(1)
.multiple_values(false)
#validator
},

Expand Down
15 changes: 15 additions & 0 deletions clap_derive/tests/options.rs
Expand Up @@ -14,7 +14,10 @@

#![allow(clippy::option_option)]

mod utils;

use clap::Clap;
use utils::*;

#[test]
fn required_option() {
Expand Down Expand Up @@ -135,6 +138,18 @@ fn optional_argument_for_optional_option() {
assert!(Opt::try_parse_from(&["test", "-a42", "-a24"]).is_err());
}

#[test]
fn option_option_help() {
#[derive(Clap, Debug)]
struct Opt {
#[clap(long, value_name = "val")]
arg: Option<Option<i32>>,
}
let help = get_help::<Opt>();
assert!(help.contains("--arg <val>"));
assert!(!help.contains("--arg <val>..."));
}

#[test]
fn two_option_options() {
#[derive(Clap, PartialEq, Debug)]
Expand Down

0 comments on commit 286fda0

Please sign in to comment.