mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
fdcee9313f
Adds parser flags to toggle whether to run the expensive clone logic for completions case. Help completion will only suggest subcommands, not args. clap_complete generator sets the flag.
49 lines
1.5 KiB
Text
49 lines
1.5 KiB
Text
|
|
use builtin;
|
|
use str;
|
|
|
|
set edit:completion:arg-completer[my-app] = {|@words|
|
|
fn spaces {|n|
|
|
builtin:repeat $n ' ' | str:join ''
|
|
}
|
|
fn cand {|text desc|
|
|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
|
|
}
|
|
var command = 'my-app'
|
|
for word $words[1..-1] {
|
|
if (str:has-prefix $word '-') {
|
|
break
|
|
}
|
|
set command = $command';'$word
|
|
}
|
|
var completions = [
|
|
&'my-app'= {
|
|
cand -c 'some config file'
|
|
cand -C 'some config file'
|
|
cand --config 'some config file'
|
|
cand --conf 'some config file'
|
|
cand -h 'Print help information'
|
|
cand --help 'Print help information'
|
|
cand -V 'Print version information'
|
|
cand --version 'Print version information'
|
|
cand test 'tests things'
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
}
|
|
&'my-app;test'= {
|
|
cand --case 'the case to test'
|
|
cand -h 'Print help information'
|
|
cand --help 'Print help information'
|
|
cand -V 'Print version information'
|
|
cand --version 'Print version information'
|
|
}
|
|
&'my-app;help'= {
|
|
cand test 'tests things'
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
}
|
|
&'my-app;help;test'= {
|
|
}
|
|
&'my-app;help;help'= {
|
|
}
|
|
]
|
|
$completions[$command]
|
|
}
|