fix(help): Match v3 usage for optional positionals

This commit is contained in:
Ed Page 2022-08-25 13:13:09 -05:00
parent 0e0c5eb218
commit df7616b820
7 changed files with 17 additions and 13 deletions

View file

@ -39,7 +39,7 @@ _my-app() {
return 0
;;
my__app__help)
opts="-c <SUBCOMMAND>..."
opts="-c [SUBCOMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0

View file

@ -39,7 +39,7 @@ _my-app() {
return 0
;;
my__app__help)
opts="<SUBCOMMAND>..."
opts="[SUBCOMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0

View file

@ -138,7 +138,7 @@ _my-app() {
return 0
;;
my__app__help)
opts="<SUBCOMMAND>..."
opts="[SUBCOMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0

View file

@ -48,7 +48,7 @@ _my-app() {
return 0
;;
my__app__help)
opts="<SUBCOMMAND>..."
opts="[SUBCOMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0

View file

@ -45,7 +45,7 @@ _my-app() {
return 0
;;
my__app__help)
opts="<SUBCOMMAND>..."
opts="[SUBCOMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@ -73,7 +73,7 @@ _my-app() {
return 0
;;
my__app__some_cmd__help)
opts="<SUBCOMMAND>..."
opts="[SUBCOMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0

View file

@ -4119,7 +4119,11 @@ pub(crate) fn render_arg_val(arg: &Arg) -> String {
debug_assert!(arg.is_takes_value_set());
for (n, val_name) in val_names.iter().enumerate() {
let arg_name = format!("<{}>", val_name);
let arg_name = if arg.is_positional() && num_vals.min_values() == 0 {
format!("[{}]", val_name)
} else {
format!("<{}>", val_name)
};
if n != 0 {
rendered.push(' ');
@ -4374,7 +4378,7 @@ mod test {
let mut p = Arg::new("pos").index(1).num_args(0..);
p._build();
assert_eq!(p.to_string(), "<pos>...");
assert_eq!(p.to_string(), "[pos]...");
}
#[test]
@ -4393,7 +4397,7 @@ mod test {
.action(ArgAction::Set);
p._build();
assert_eq!(p.to_string(), "<pos>");
assert_eq!(p.to_string(), "[pos]");
}
#[test]

View file

@ -2065,7 +2065,7 @@ USAGE:
myapp help [SUBCOMMAND]...
ARGS:
<SUBCOMMAND>... The subcommand whose help message to display
[SUBCOMMAND]... The subcommand whose help message to display
";
let cmd = Command::new("myapp")
@ -2083,7 +2083,7 @@ USAGE:
myapp subcmd help [SUBCOMMAND]...
ARGS:
<SUBCOMMAND>... The subcommand whose help message to display
[SUBCOMMAND]... The subcommand whose help message to display
";
let cmd = Command::new("myapp")
@ -2569,7 +2569,7 @@ USAGE:
example help [SUBCOMMAND]...
ARGS:
<SUBCOMMAND>... The subcommand whose help message to display
[SUBCOMMAND]... The subcommand whose help message to display
",
false,
);
@ -2612,7 +2612,7 @@ USAGE:
example help [SUBCOMMAND]...
ARGS:
<SUBCOMMAND>... The subcommand whose help message to display
[SUBCOMMAND]... The subcommand whose help message to display
",
false,
);