Make multiple_values false with Option<Option<...>>

This commit is contained in:
patrick-gu 2021-08-01 14:50:31 -07:00
parent 4bec66dd03
commit eca8ba6098
2 changed files with 16 additions and 1 deletions

View file

@ -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
},

View file

@ -14,7 +14,10 @@
#![allow(clippy::option_option)]
mod utils;
use clap::Clap;
use utils::*;
#[test]
fn required_option() {
@ -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)]