• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2use builtin;
3use str;
4
5set edit:completion:arg-completer[my-app] = {|@words|
6    fn spaces {|n|
7        builtin:repeat $n ' ' | str:join ''
8    }
9    fn cand {|text desc|
10        edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
11    }
12    var command = 'my-app'
13    for word $words[1..-1] {
14        if (str:has-prefix $word '-') {
15            break
16        }
17        set command = $command';'$word
18    }
19    var completions = [
20        &'my-app'= {
21            cand -o 'cmd option'
22            cand -O 'cmd option'
23            cand --option 'cmd option'
24            cand --opt 'cmd option'
25            cand -f 'cmd flag'
26            cand -F 'cmd flag'
27            cand --flag 'cmd flag'
28            cand --flg 'cmd flag'
29            cand -h 'Print help'
30            cand --help 'Print help'
31            cand -V 'Print version'
32            cand --version 'Print version'
33        }
34    ]
35    $completions[$command]
36}
37