1#compdef my-app 2 3autoload -U is-at-least 4 5_my-app() { 6 typeset -A opt_args 7 typeset -a _arguments_options 8 local ret=1 9 10 if is-at-least 5.2; then 11 _arguments_options=(-s -S -C) 12 else 13 _arguments_options=(-s -C) 14 fi 15 16 local context curcontext="$curcontext" state line 17 _arguments "${_arguments_options[@]}" \ 18'*-c[some config file]' \ 19'*-C[some config file]' \ 20'*--config[some config file]' \ 21'*--conf[some config file]' \ 22'-h[Print help]' \ 23'--help[Print help]' \ 24'-V[Print version]' \ 25'--version[Print version]' \ 26'::file -- some input file:_files' \ 27'::choice:(first second)' \ 28":: :_my-app_commands" \ 29"*::: :->my-app" \ 30&& ret=0 31 case $state in 32 (my-app) 33 words=($line[3] "${words[@]}") 34 (( CURRENT += 1 )) 35 curcontext="${curcontext%:*:*}:my-app-command-$line[3]:" 36 case $line[3] in 37 (test) 38_arguments "${_arguments_options[@]}" \ 39'--case=[the case to test]: : ' \ 40'-h[Print help]' \ 41'--help[Print help]' \ 42'-V[Print version]' \ 43'--version[Print version]' \ 44&& ret=0 45;; 46(help) 47_arguments "${_arguments_options[@]}" \ 48":: :_my-app__help_commands" \ 49"*::: :->help" \ 50&& ret=0 51 52 case $state in 53 (help) 54 words=($line[1] "${words[@]}") 55 (( CURRENT += 1 )) 56 curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:" 57 case $line[1] in 58 (test) 59_arguments "${_arguments_options[@]}" \ 60&& ret=0 61;; 62(help) 63_arguments "${_arguments_options[@]}" \ 64&& ret=0 65;; 66 esac 67 ;; 68esac 69;; 70 esac 71 ;; 72esac 73} 74 75(( $+functions[_my-app_commands] )) || 76_my-app_commands() { 77 local commands; commands=( 78'test:tests things' \ 79'help:Print this message or the help of the given subcommand(s)' \ 80 ) 81 _describe -t commands 'my-app commands' commands "$@" 82} 83(( $+functions[_my-app__help_commands] )) || 84_my-app__help_commands() { 85 local commands; commands=( 86'test:tests things' \ 87'help:Print this message or the help of the given subcommand(s)' \ 88 ) 89 _describe -t commands 'my-app help commands' commands "$@" 90} 91(( $+functions[_my-app__help__help_commands] )) || 92_my-app__help__help_commands() { 93 local commands; commands=() 94 _describe -t commands 'my-app help help commands' commands "$@" 95} 96(( $+functions[_my-app__help__test_commands] )) || 97_my-app__help__test_commands() { 98 local commands; commands=() 99 _describe -t commands 'my-app help test commands' commands "$@" 100} 101(( $+functions[_my-app__test_commands] )) || 102_my-app__test_commands() { 103 local commands; commands=() 104 _describe -t commands 'my-app test commands' commands "$@" 105} 106 107_my-app "$@" 108