clap/clap_complete/tests/snapshots/basic.elvish
Alexis (Poliorcetics) Bourget e782775229 fix(complete): Handle newlines in command/arg descriptions
Found while trying to add Nushell completions to
[`jj`](https://github.com/martinvonz/jj).
2024-02-16 16:17:22 -06:00

44 lines
1.2 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 'c'
cand -v 'v'
cand -h 'Print help'
cand --help 'Print help'
cand test 'Subcommand with a second line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'my-app;test'= {
cand -d 'd'
cand -c 'c'
cand -h 'Print help'
cand --help 'Print help'
}
&'my-app;help'= {
cand test 'Subcommand with a second line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'my-app;help;test'= {
}
&'my-app;help;help'= {
}
]
$completions[$command]
}