mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
fix(gen): in bash, pass use possible_values if available
Change-Id: I7a54821666f0ba366379d6cac83898fcd9b76ee6
This commit is contained in:
parent
c5296977e5
commit
de1c764905
2 changed files with 17 additions and 5 deletions
|
@ -201,9 +201,20 @@ fn all_options_for_path(app: &App, path: &str) -> String {
|
|||
longs = utils::longs_and_visible_aliases(p)
|
||||
.iter()
|
||||
.fold(String::new(), |acc, l| format!("{} --{}", acc, l)),
|
||||
pos = p
|
||||
.get_positionals()
|
||||
.fold(String::new(), |acc, p| format!("{} {}", acc, p)),
|
||||
pos = p.get_positionals().fold(String::new(), |acc, p| {
|
||||
if let Some(vals) = p.get_possible_values() {
|
||||
format!(
|
||||
"{} {}",
|
||||
acc,
|
||||
vals.iter()
|
||||
.map(|x| x.get_name())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
)
|
||||
} else {
|
||||
format!("{} {}", acc, p)
|
||||
}
|
||||
}),
|
||||
subcmds = scs.join(" "),
|
||||
);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> {
|
|||
.value_hint(ValueHint::FilePath)
|
||||
.about("some input file"),
|
||||
)
|
||||
.arg(Arg::new("choice").possible_values(["first", "second"]))
|
||||
.subcommand(
|
||||
App::new("test").about("tests things").arg(
|
||||
Arg::new("case")
|
||||
|
@ -57,7 +58,7 @@ static BASH: &str = r#"_myapp() {
|
|||
|
||||
case "${cmd}" in
|
||||
myapp)
|
||||
opts=" -h -V --help --version <file> test help"
|
||||
opts=" -h -V --help --version <file> first second test help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -160,7 +161,7 @@ static BASH_SPECIAL_CMDS: &str = r#"_my_app() {
|
|||
|
||||
case "${cmd}" in
|
||||
my_app)
|
||||
opts=" -h -V --help --version <file> test some_cmd some-cmd-with-hypens help"
|
||||
opts=" -h -V --help --version <file> first second test some_cmd some-cmd-with-hypens help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
|
Loading…
Reference in a new issue