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 -c 'some config file' 22 cand -C 'some config file' 23 cand --config 'some config file' 24 cand --conf 'some config file' 25 cand -h 'Print help' 26 cand --help 'Print help' 27 cand -V 'Print version' 28 cand --version 'Print version' 29 cand test 'tests things' 30 cand help 'Print this message or the help of the given subcommand(s)' 31 } 32 &'my-app;test'= { 33 cand --case 'the case to test' 34 cand -h 'Print help' 35 cand --help 'Print help' 36 cand -V 'Print version' 37 cand --version 'Print version' 38 } 39 &'my-app;help'= { 40 cand test 'tests things' 41 cand help 'Print this message or the help of the given subcommand(s)' 42 } 43 &'my-app;help;test'= { 44 } 45 &'my-app;help;help'= { 46 } 47 ] 48 $completions[$command] 49} 50