diff --git a/src/parser.rs b/src/parser.rs index a38879a5..5d0669ad 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -350,7 +350,14 @@ fn parse_param_modifer(input: &str) -> nom::IResult<&str, ParamData> { |(mut arg, multi_char)| { let modifier = match multi_char { Some(c) => Modifier::MultiCharOptional(c), - None => Modifier::MultipleOptional, + None => { + if let Some(name) = arg.name.strip_suffix('-') { + arg.name = name.to_string(); + Modifier::Prefixed + } else { + Modifier::MultipleOptional + } + } }; arg.modifer = modifier; arg @@ -367,13 +374,7 @@ fn parse_param_modifer(input: &str) -> nom::IResult<&str, ParamData> { arg }, ), - map(parse_param_name, |mut arg| { - if let Some(name) = arg.name.strip_suffix('-') { - arg.name = name.to_string(); - arg.modifer = Modifier::Prefixed; - } - arg - }), + parse_param_name, ))(input) } diff --git a/tests/compgen.rs b/tests/compgen.rs index 5d115103..2143439c 100644 --- a/tests/compgen.rs +++ b/tests/compgen.rs @@ -594,8 +594,8 @@ _choice_fn() { #[test] fn option_prefixed() { let script = r###" -# @option -D-[`_choice_fn`] -# @option -X --ox-[`_choice_fn`] +# @option -D-*[`_choice_fn`] +# @option -X --ox-*[`_choice_fn`] _choice_fn() { echo VAR1=value1 echo VAR2=value2 diff --git a/tests/spec.rs b/tests/spec.rs index 64c0c8bc..69a777e5 100644 --- a/tests/spec.rs +++ b/tests/spec.rs @@ -198,7 +198,7 @@ fn option_terminated() { #[test] fn option_prefixed() { let script = r###" -# @option -D- +# @option -D-* "###; snapshot!(script, &["prog", "-D", "v1", "-Dv2=foo"]); }