• 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[]' \
19'(-c)-v[]' \
20'-h[Print help]' \
21'--help[Print help]' \
22":: :_my-app_commands" \
23"*::: :->my-app" \
24&& ret=0
25    case $state in
26    (my-app)
27        words=($line[1] "${words[@]}")
28        (( CURRENT += 1 ))
29        curcontext="${curcontext%:*:*}:my-app-command-$line[1]:"
30        case $line[1] in
31            (test)
32_arguments "${_arguments_options[@]}" \
33'*-d[]' \
34'-c[]' \
35'-h[Print help]' \
36'--help[Print help]' \
37&& ret=0
38;;
39(help)
40_arguments "${_arguments_options[@]}" \
41":: :_my-app__help_commands" \
42"*::: :->help" \
43&& ret=0
44
45    case $state in
46    (help)
47        words=($line[1] "${words[@]}")
48        (( CURRENT += 1 ))
49        curcontext="${curcontext%:*:*}:my-app-help-command-$line[1]:"
50        case $line[1] in
51            (test)
52_arguments "${_arguments_options[@]}" \
53&& ret=0
54;;
55(help)
56_arguments "${_arguments_options[@]}" \
57&& ret=0
58;;
59        esac
60    ;;
61esac
62;;
63        esac
64    ;;
65esac
66}
67
68(( $+functions[_my-app_commands] )) ||
69_my-app_commands() {
70    local commands; commands=(
71'test:Subcommand' \
72'help:Print this message or the help of the given subcommand(s)' \
73    )
74    _describe -t commands 'my-app commands' commands "$@"
75}
76(( $+functions[_my-app__help_commands] )) ||
77_my-app__help_commands() {
78    local commands; commands=(
79'test:Subcommand' \
80'help:Print this message or the help of the given subcommand(s)' \
81    )
82    _describe -t commands 'my-app help commands' commands "$@"
83}
84(( $+functions[_my-app__help__help_commands] )) ||
85_my-app__help__help_commands() {
86    local commands; commands=()
87    _describe -t commands 'my-app help help commands' commands "$@"
88}
89(( $+functions[_my-app__help__test_commands] )) ||
90_my-app__help__test_commands() {
91    local commands; commands=()
92    _describe -t commands 'my-app help test commands' commands "$@"
93}
94(( $+functions[_my-app__test_commands] )) ||
95_my-app__test_commands() {
96    local commands; commands=()
97    _describe -t commands 'my-app test commands' commands "$@"
98}
99
100if [ "$funcstack[1]" = "_my-app" ]; then
101    _my-app "$@"
102else
103    compdef _my-app my-app
104fi
105