• 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'-h[Print help]' \
49'--help[Print help]' \
50'-V[Print version]' \
51'--version[Print version]' \
52":: :_my-app__some_cmd_commands" \
53"*::: :->some_cmd" \
54&& ret=0
55
56    case $state in
57    (some_cmd)
58        words=($line[1] "${words[@]}")
59        (( CURRENT += 1 ))
60        curcontext="${curcontext%:*:*}:my-app-some_cmd-command-$line[1]:"
61        case $line[1] in
62            (sub_cmd)
63_arguments "${_arguments_options[@]}" \
64'--config=[the other case to test]: :((Lest\ quotes,\ aren'\''t\ escaped.\:"help,with,comma"
65Second\ to\ trigger\ display\ of\ options\:""))' \
66'-h[Print help (see more with '\''--help'\'')]' \
67'--help[Print help (see more with '\''--help'\'')]' \
68'-V[Print version]' \
69'--version[Print version]' \
70&& ret=0
71;;
72(help)
73_arguments "${_arguments_options[@]}" \
74":: :_my-app__some_cmd__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-some_cmd-help-command-$line[1]:"
83        case $line[1] in
84            (sub_cmd)
85_arguments "${_arguments_options[@]}" \
86&& ret=0
87;;
88(help)
89_arguments "${_arguments_options[@]}" \
90&& ret=0
91;;
92        esac
93    ;;
94esac
95;;
96        esac
97    ;;
98esac
99;;
100(help)
101_arguments "${_arguments_options[@]}" \
102":: :_my-app__help_commands" \
103"*::: :->help" \
104&& ret=0
105
106    case $state in
107    (help)
108        words=($line[1] "${words[@]}")
109        (( CURRENT += 1 ))
110        curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
111        case $line[1] in
112            (test)
113_arguments "${_arguments_options[@]}" \
114&& ret=0
115;;
116(some_cmd)
117_arguments "${_arguments_options[@]}" \
118":: :_my-app__help__some_cmd_commands" \
119"*::: :->some_cmd" \
120&& ret=0
121
122    case $state in
123    (some_cmd)
124        words=($line[1] "${words[@]}")
125        (( CURRENT += 1 ))
126        curcontext="${curcontext%:*:*}:my-app-help-some_cmd-command-$line[1]:"
127        case $line[1] in
128            (sub_cmd)
129_arguments "${_arguments_options[@]}" \
130&& ret=0
131;;
132        esac
133    ;;
134esac
135;;
136(help)
137_arguments "${_arguments_options[@]}" \
138&& ret=0
139;;
140        esac
141    ;;
142esac
143;;
144        esac
145    ;;
146esac
147}
148
149(( $+functions[_my-app_commands] )) ||
150_my-app_commands() {
151    local commands; commands=(
152'test:tests things' \
153'some_cmd:top level subcommand' \
154'some_cmd_alias:top level subcommand' \
155'help:Print this message or the help of the given subcommand(s)' \
156    )
157    _describe -t commands 'my-app commands' commands "$@"
158}
159(( $+functions[_my-app__help_commands] )) ||
160_my-app__help_commands() {
161    local commands; commands=(
162'test:tests things' \
163'some_cmd:top level subcommand' \
164'help:Print this message or the help of the given subcommand(s)' \
165    )
166    _describe -t commands 'my-app help commands' commands "$@"
167}
168(( $+functions[_my-app__help__help_commands] )) ||
169_my-app__help__help_commands() {
170    local commands; commands=()
171    _describe -t commands 'my-app help help commands' commands "$@"
172}
173(( $+functions[_my-app__some_cmd__help_commands] )) ||
174_my-app__some_cmd__help_commands() {
175    local commands; commands=(
176'sub_cmd:sub-subcommand' \
177'help:Print this message or the help of the given subcommand(s)' \
178    )
179    _describe -t commands 'my-app some_cmd help commands' commands "$@"
180}
181(( $+functions[_my-app__some_cmd__help__help_commands] )) ||
182_my-app__some_cmd__help__help_commands() {
183    local commands; commands=()
184    _describe -t commands 'my-app some_cmd help help commands' commands "$@"
185}
186(( $+functions[_my-app__help__some_cmd_commands] )) ||
187_my-app__help__some_cmd_commands() {
188    local commands; commands=(
189'sub_cmd:sub-subcommand' \
190    )
191    _describe -t commands 'my-app help some_cmd commands' commands "$@"
192}
193(( $+functions[_my-app__some_cmd_commands] )) ||
194_my-app__some_cmd_commands() {
195    local commands; commands=(
196'sub_cmd:sub-subcommand' \
197'help:Print this message or the help of the given subcommand(s)' \
198    )
199    _describe -t commands 'my-app some_cmd commands' commands "$@"
200}
201(( $+functions[_my-app__help__some_cmd__sub_cmd_commands] )) ||
202_my-app__help__some_cmd__sub_cmd_commands() {
203    local commands; commands=()
204    _describe -t commands 'my-app help some_cmd sub_cmd commands' commands "$@"
205}
206(( $+functions[_my-app__some_cmd__help__sub_cmd_commands] )) ||
207_my-app__some_cmd__help__sub_cmd_commands() {
208    local commands; commands=()
209    _describe -t commands 'my-app some_cmd help sub_cmd commands' commands "$@"
210}
211(( $+functions[_my-app__some_cmd__sub_cmd_commands] )) ||
212_my-app__some_cmd__sub_cmd_commands() {
213    local commands; commands=()
214    _describe -t commands 'my-app some_cmd sub_cmd commands' commands "$@"
215}
216(( $+functions[_my-app__help__test_commands] )) ||
217_my-app__help__test_commands() {
218    local commands; commands=()
219    _describe -t commands 'my-app help test commands' commands "$@"
220}
221(( $+functions[_my-app__test_commands] )) ||
222_my-app__test_commands() {
223    local commands; commands=()
224    _describe -t commands 'my-app test commands' commands "$@"
225}
226
227if [ "$funcstack[1]" = "_my-app" ]; then
228    _my-app "$@"
229else
230    compdef _my-app my-app
231fi
232