2022-03-07 20:03:46 +00:00
|
|
|
|
|
|
|
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'
|
2023-01-03 16:49:43 +00:00
|
|
|
cand -h 'Print help'
|
|
|
|
cand --help 'Print help'
|
|
|
|
cand -V 'Print version'
|
|
|
|
cand --version 'Print version'
|
2022-03-07 20:03:46 +00:00
|
|
|
cand test 'tests things'
|
|
|
|
cand some_cmd 'top level subcommand'
|
|
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
|
|
}
|
|
|
|
&'my-app;test'= {
|
|
|
|
cand --case 'the case to test'
|
2023-01-03 16:49:43 +00:00
|
|
|
cand -h 'Print help'
|
|
|
|
cand --help 'Print help'
|
|
|
|
cand -V 'Print version'
|
|
|
|
cand --version 'Print version'
|
2022-03-07 20:03:46 +00:00
|
|
|
}
|
|
|
|
&'my-app;some_cmd'= {
|
2023-01-03 16:49:43 +00:00
|
|
|
cand -h 'Print help'
|
|
|
|
cand --help 'Print help'
|
|
|
|
cand -V 'Print version'
|
|
|
|
cand --version 'Print version'
|
2022-03-07 20:03:46 +00:00
|
|
|
cand sub_cmd 'sub-subcommand'
|
|
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
|
|
}
|
|
|
|
&'my-app;some_cmd;sub_cmd'= {
|
|
|
|
cand --config 'the other case to test'
|
2023-01-03 16:49:43 +00:00
|
|
|
cand -h 'Print help (see more with ''--help'')'
|
|
|
|
cand --help 'Print help (see more with ''--help'')'
|
|
|
|
cand -V 'Print version'
|
|
|
|
cand --version 'Print version'
|
2022-03-07 20:03:46 +00:00
|
|
|
}
|
|
|
|
&'my-app;some_cmd;help'= {
|
2022-08-25 05:44:07 +00:00
|
|
|
cand sub_cmd 'sub-subcommand'
|
|
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
|
|
}
|
|
|
|
&'my-app;some_cmd;help;sub_cmd'= {
|
|
|
|
}
|
|
|
|
&'my-app;some_cmd;help;help'= {
|
2022-03-07 20:03:46 +00:00
|
|
|
}
|
|
|
|
&'my-app;help'= {
|
2022-08-25 05:44:07 +00:00
|
|
|
cand test 'tests things'
|
|
|
|
cand some_cmd 'top level subcommand'
|
|
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
|
|
}
|
|
|
|
&'my-app;help;test'= {
|
|
|
|
}
|
|
|
|
&'my-app;help;some_cmd'= {
|
|
|
|
cand sub_cmd 'sub-subcommand'
|
|
|
|
}
|
|
|
|
&'my-app;help;some_cmd;sub_cmd'= {
|
|
|
|
}
|
|
|
|
&'my-app;help;help'= {
|
2022-03-07 20:03:46 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
$completions[$command]
|
|
|
|
}
|