mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
36bc641648
This is an intermediate solution for #4408. As there were no agreeed upon goals, I went with what I felt read well and that I saw commonly used on non-clap commands. - "information" isn't really a necessary word. - I originally favored `Print this help` but realied that doesn't read correctly in completions. - Besides being shorter, the reason for the flipped short/long hint is it gives people the context they need for scanning, emphasizing "summary" and "more". Fixes #4409
80 lines
2.5 KiB
Text
80 lines
2.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'
|
|
cand --help 'Print help'
|
|
cand -V 'Print version'
|
|
cand --version 'Print version'
|
|
cand test 'tests things'
|
|
cand some_cmd 'tests other things'
|
|
cand some-cmd-with-hyphens 'some-cmd-with-hyphens'
|
|
cand some-hidden-cmd 'some-hidden-cmd'
|
|
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'
|
|
cand --help 'Print help'
|
|
cand -V 'Print version'
|
|
cand --version 'Print version'
|
|
}
|
|
&'my-app;some_cmd'= {
|
|
cand --config 'the other case to test'
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
cand -V 'Print version'
|
|
cand --version 'Print version'
|
|
}
|
|
&'my-app;some-cmd-with-hyphens'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
cand -V 'Print version'
|
|
cand --version 'Print version'
|
|
}
|
|
&'my-app;some-hidden-cmd'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
cand -V 'Print version'
|
|
cand --version 'Print version'
|
|
}
|
|
&'my-app;help'= {
|
|
cand test 'tests things'
|
|
cand some_cmd 'tests other things'
|
|
cand some-cmd-with-hyphens 'some-cmd-with-hyphens'
|
|
cand some-hidden-cmd 'some-hidden-cmd'
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
}
|
|
&'my-app;help;test'= {
|
|
}
|
|
&'my-app;help;some_cmd'= {
|
|
}
|
|
&'my-app;help;some-cmd-with-hyphens'= {
|
|
}
|
|
&'my-app;help;some-hidden-cmd'= {
|
|
}
|
|
&'my-app;help;help'= {
|
|
}
|
|
]
|
|
$completions[$command]
|
|
}
|