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 some_cmd 'tests other things' 31 cand some-cmd-with-hyphens 'some-cmd-with-hyphens' 32 cand some-hidden-cmd 'some-hidden-cmd' 33 cand help 'Print this message or the help of the given subcommand(s)' 34 } 35 &'my-app;test'= { 36 cand --case 'the case to test' 37 cand -h 'Print help' 38 cand --help 'Print help' 39 cand -V 'Print version' 40 cand --version 'Print version' 41 } 42 &'my-app;some_cmd'= { 43 cand --config 'the other case to test' 44 cand -h 'Print help' 45 cand --help 'Print help' 46 cand -V 'Print version' 47 cand --version 'Print version' 48 } 49 &'my-app;some-cmd-with-hyphens'= { 50 cand -h 'Print help' 51 cand --help 'Print help' 52 cand -V 'Print version' 53 cand --version 'Print version' 54 } 55 &'my-app;some-hidden-cmd'= { 56 cand -h 'Print help' 57 cand --help 'Print help' 58 cand -V 'Print version' 59 cand --version 'Print version' 60 } 61 &'my-app;help'= { 62 cand test 'tests things' 63 cand some_cmd 'tests other things' 64 cand some-cmd-with-hyphens 'some-cmd-with-hyphens' 65 cand some-hidden-cmd 'some-hidden-cmd' 66 cand help 'Print this message or the help of the given subcommand(s)' 67 } 68 &'my-app;help;test'= { 69 } 70 &'my-app;help;some_cmd'= { 71 } 72 &'my-app;help;some-cmd-with-hyphens'= { 73 } 74 &'my-app;help;some-hidden-cmd'= { 75 } 76 &'my-app;help;help'= { 77 } 78 ] 79 $completions[$command] 80} 81