diff --git a/src/param.rs b/src/param.rs index 2a3f8aee..c6caf645 100644 --- a/src/param.rs +++ b/src/param.rs @@ -574,7 +574,7 @@ impl Modifier { Self::MultiCharOptional(c) => format!("*{c}"), Self::MultiCharRequired(c) => format!("+{c}"), Self::Terminated => "~".to_string(), - Self::Prefixed => "%".to_string(), + Self::Prefixed => "-".to_string(), } } } diff --git a/src/parser.rs b/src/parser.rs index 2296beb7..d87769e3 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -345,10 +345,6 @@ fn parse_param_modifer(input: &str) -> nom::IResult<&str, ParamData> { arg.modifer = Modifier::Terminated; arg }), - map(terminated(parse_param_name, tag("%")), |mut arg| { - arg.modifer = Modifier::Prefixed; - arg - }), map( pair(parse_param_name, preceded(tag("*"), opt(parse_multi_char))), |(mut arg, multi_char)| { @@ -371,7 +367,13 @@ fn parse_param_modifer(input: &str) -> nom::IResult<&str, ParamData> { arg }, ), - parse_param_name, + map(parse_param_name, |mut arg| { + if let Some(name) = arg.name.strip_suffix('-') { + arg.name = name.to_string(); + arg.modifer = Modifier::Prefixed; + } + arg + }), ))(input) } @@ -806,7 +808,8 @@ mod tests { assert_parse_option_arg!("-f![a|b]"); assert_parse_option_arg!("-f![`_foo`]"); assert_parse_option_arg!("-f![=a|b]"); - assert_parse_option_arg!("-D%"); + assert_parse_option_arg!("-D-"); + assert_parse_option_arg!("-D--"); } #[test] diff --git a/tests/compgen.rs b/tests/compgen.rs index ead7ea6e..c2d7ac71 100644 --- a/tests/compgen.rs +++ b/tests/compgen.rs @@ -567,8 +567,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 abc32c40..c5eb6fd8 100644 --- a/tests/spec.rs +++ b/tests/spec.rs @@ -199,7 +199,7 @@ fn option_terminated() { #[test] fn option_prefixed() { let script = r###" -# @option -D% +# @option -D- "###; snapshot!(script, &["prog", "-D", "v1", "-Dv2=foo"]); }