• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(some_cmd)
47_arguments "${_arguments_options[@]}" \
48'--config=[the other case to test]: : ' \
49'-h[Print help]' \
50'--help[Print help]' \
51'-V[Print version]' \
52'--version[Print version]' \
53'*::path:' \
54&& ret=0
55;;
56(some-cmd-with-hyphens)
57_arguments "${_arguments_options[@]}" \
58'-h[Print help]' \
59'--help[Print help]' \
60'-V[Print version]' \
61'--version[Print version]' \
62&& ret=0
63;;
64(some-hidden-cmd)
65_arguments "${_arguments_options[@]}" \
66'-h[Print help]' \
67'--help[Print help]' \
68'-V[Print version]' \
69'--version[Print version]' \
70&& ret=0
71;;
72(help)
73_arguments "${_arguments_options[@]}" \
74":: :_my-app__help_commands" \
75"*::: :->help" \
76&& ret=0
77
78    case $state in
79    (help)
80        words=($line[1] "${words[@]}")
81        (( CURRENT += 1 ))
82        curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
83        case $line[1] in
84            (test)
85_arguments "${_arguments_options[@]}" \
86&& ret=0
87;;
88(some_cmd)
89_arguments "${_arguments_options[@]}" \
90&& ret=0
91;;
92(some-cmd-with-hyphens)
93_arguments "${_arguments_options[@]}" \
94&& ret=0
95;;
96(some-hidden-cmd)
97_arguments "${_arguments_options[@]}" \
98&& ret=0
99;;
100(help)
101_arguments "${_arguments_options[@]}" \
102&& ret=0
103;;
104        esac
105    ;;
106esac
107;;
108        esac
109    ;;
110esac
111}
112
113(( $+functions[_my-app_commands] )) ||
114_my-app_commands() {
115    local commands; commands=(
116'test:tests things' \
117'some_cmd:tests other things' \
118'some-cmd-with-hyphens:' \
119'some-hidden-cmd:' \
120'help:Print this message or the help of the given subcommand(s)' \
121    )
122    _describe -t commands 'my-app commands' commands "$@"
123}
124(( $+functions[_my-app__help_commands] )) ||
125_my-app__help_commands() {
126    local commands; commands=(
127'test:tests things' \
128'some_cmd:tests other things' \
129'some-cmd-with-hyphens:' \
130'some-hidden-cmd:' \
131'help:Print this message or the help of the given subcommand(s)' \
132    )
133    _describe -t commands 'my-app help commands' commands "$@"
134}
135(( $+functions[_my-app__help__help_commands] )) ||
136_my-app__help__help_commands() {
137    local commands; commands=()
138    _describe -t commands 'my-app help help commands' commands "$@"
139}
140(( $+functions[_my-app__help__some-cmd-with-hyphens_commands] )) ||
141_my-app__help__some-cmd-with-hyphens_commands() {
142    local commands; commands=()
143    _describe -t commands 'my-app help some-cmd-with-hyphens commands' commands "$@"
144}
145(( $+functions[_my-app__some-cmd-with-hyphens_commands] )) ||
146_my-app__some-cmd-with-hyphens_commands() {
147    local commands; commands=()
148    _describe -t commands 'my-app some-cmd-with-hyphens commands' commands "$@"
149}
150(( $+functions[_my-app__help__some-hidden-cmd_commands] )) ||
151_my-app__help__some-hidden-cmd_commands() {
152    local commands; commands=()
153    _describe -t commands 'my-app help some-hidden-cmd commands' commands "$@"
154}
155(( $+functions[_my-app__some-hidden-cmd_commands] )) ||
156_my-app__some-hidden-cmd_commands() {
157    local commands; commands=()
158    _describe -t commands 'my-app some-hidden-cmd commands' commands "$@"
159}
160(( $+functions[_my-app__help__some_cmd_commands] )) ||
161_my-app__help__some_cmd_commands() {
162    local commands; commands=()
163    _describe -t commands 'my-app help some_cmd commands' commands "$@"
164}
165(( $+functions[_my-app__some_cmd_commands] )) ||
166_my-app__some_cmd_commands() {
167    local commands; commands=()
168    _describe -t commands 'my-app some_cmd commands' commands "$@"
169}
170(( $+functions[_my-app__help__test_commands] )) ||
171_my-app__help__test_commands() {
172    local commands; commands=()
173    _describe -t commands 'my-app help test commands' commands "$@"
174}
175(( $+functions[_my-app__test_commands] )) ||
176_my-app__test_commands() {
177    local commands; commands=()
178    _describe -t commands 'my-app test commands' commands "$@"
179}
180
181_my-app "$@"
182