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
88 lines
3 KiB
Text
88 lines
3 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 --single-quotes 'Can be ''always'', ''auto'', or ''never'''
|
|
cand --double-quotes 'Can be "always", "auto", or "never"'
|
|
cand --backticks 'For more information see `echo test`'
|
|
cand --backslash 'Avoid ''\n'''
|
|
cand --brackets 'List packages [filter]'
|
|
cand --expansions 'Execute the shell command with $SHELL'
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
cand -V 'Print version'
|
|
cand --version 'Print version'
|
|
cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never'''
|
|
cand cmd-double-quotes 'Can be "always", "auto", or "never"'
|
|
cand cmd-backticks 'For more information see `echo test`'
|
|
cand cmd-backslash 'Avoid ''\n'''
|
|
cand cmd-brackets 'List packages [filter]'
|
|
cand cmd-expansions 'Execute the shell command with $SHELL'
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
}
|
|
&'my-app;cmd-single-quotes'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
}
|
|
&'my-app;cmd-double-quotes'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
}
|
|
&'my-app;cmd-backticks'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
}
|
|
&'my-app;cmd-backslash'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
}
|
|
&'my-app;cmd-brackets'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
}
|
|
&'my-app;cmd-expansions'= {
|
|
cand -h 'Print help'
|
|
cand --help 'Print help'
|
|
}
|
|
&'my-app;help'= {
|
|
cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never'''
|
|
cand cmd-double-quotes 'Can be "always", "auto", or "never"'
|
|
cand cmd-backticks 'For more information see `echo test`'
|
|
cand cmd-backslash 'Avoid ''\n'''
|
|
cand cmd-brackets 'List packages [filter]'
|
|
cand cmd-expansions 'Execute the shell command with $SHELL'
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
}
|
|
&'my-app;help;cmd-single-quotes'= {
|
|
}
|
|
&'my-app;help;cmd-double-quotes'= {
|
|
}
|
|
&'my-app;help;cmd-backticks'= {
|
|
}
|
|
&'my-app;help;cmd-backslash'= {
|
|
}
|
|
&'my-app;help;cmd-brackets'= {
|
|
}
|
|
&'my-app;help;cmd-expansions'= {
|
|
}
|
|
&'my-app;help;help'= {
|
|
}
|
|
]
|
|
$completions[$command]
|
|
}
|