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 'c' 22 cand -v 'v' 23 cand -h 'Print help' 24 cand --help 'Print help' 25 cand test 'Subcommand' 26 cand help 'Print this message or the help of the given subcommand(s)' 27 } 28 &'my-app;test'= { 29 cand -d 'd' 30 cand -c 'c' 31 cand -h 'Print help' 32 cand --help 'Print help' 33 } 34 &'my-app;help'= { 35 cand test 'Subcommand' 36 cand help 'Print this message or the help of the given subcommand(s)' 37 } 38 &'my-app;help;test'= { 39 } 40 &'my-app;help;help'= { 41 } 42 ] 43 $completions[$command] 44} 45