use builtin; use str; set edit:completion:arg-completer[complate] = {|@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 = 'complate' for word $words[1..-1] { if (str:has-prefix $word '-') { break } set command = $command';'$word } var completions = [ &'complate'= { cand -e 'enables experimental features' cand --experimental 'enables experimental features' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' cand man 'Renders the manual.' cand autocomplete 'Renders shell completion scripts.' cand init 'Initializes a dummy default configuration in "./.complate/config.yaml".' cand schema 'Renders the configuration schema.' cand render 'Renders a template by replacing values as specified by the configuration.' cand help 'Print this message or the help of the given subcommand(s)' } &'complate;man'= { cand -o 'o' cand --out 'out' cand -f 'f' cand --format 'format' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'complate;autocomplete'= { cand -o 'o' cand --out 'out' cand -s 's' cand --shell 'shell' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'complate;init'= { cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'complate;schema'= { cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'complate;render'= { cand -c 'The configuration file to use.' cand --config 'The configuration file to use.' cand -t 'Specify the template to use from the config and skip it''s selection.' cand --template 'Specify the template to use from the config and skip it''s selection.' cand -b 'The execution backend (cli=native-terminal, ui=ui emulator in terminal).' cand --backend 'The execution backend (cli=native-terminal, ui=ui emulator in terminal).' cand -v 'Overrides a certain value definition with a string.' cand --value 'Overrides a certain value definition with a string.' cand --trust 'Enables the shell command execution. This is potentially insecure and should only be done for trustworthy sources.' cand -l 'Defines that the templating is done in non-strict mode (allow missing value for variable).' cand --loose 'Defines that the templating is done in non-strict mode (allow missing value for variable).' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'complate;help'= { cand man 'Renders the manual.' cand autocomplete 'Renders shell completion scripts.' cand init 'Initializes a dummy default configuration in "./.complate/config.yaml".' cand schema 'Renders the configuration schema.' cand render 'Renders a template by replacing values as specified by the configuration.' cand help 'Print this message or the help of the given subcommand(s)' } &'complate;help;man'= { } &'complate;help;autocomplete'= { } &'complate;help;init'= { } &'complate;help;schema'= { } &'complate;help;render'= { } &'complate;help;help'= { } ] $completions[$command] }