Debian Codegraph @

completion/_kameleon

raw
1 #compdef kameleon
2
3 # This is ZSH completion script based on the kameleon 2.6.0.dev API
4 #
5 # Author: Michael Mercier
6 #
7 # This was made with the help of this howto:
8 # https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org
9 # and with the _git completion file
10
11 # Helpers
12 template_list="kameleon template list | tail -n +4 | cut -f1 -d'|'"
13
14 # Repository kameleon subcommands
15 _kameleon_repository () {
16 local curcontext=$curcontext state line ret=1
17 declare -A opt_args
18
19 _arguments -C \
20 ': :->command' \
21 '*:: :->option-or-argument' && ret=0
22
23 case $state in
24 (command)
25 declare -a commands
26
27 commands=(
28 add:'Adds a new named NAME repository at URL'
29 help:'Describe available subcommands or one specific subcommand'
30 list:'Lists available repositories'
31 update:'Update specified repository')
32
33 _describe -t commands command commands && ret=0
34 ;;
35 (option-or-argument)
36 curcontext=${curcontext%:*}-$line[1]:
37
38 case $line[1] in
39 (add)
40 _arguments \
41 '1:Repository local name' \
42 '2:Repository URL or local path:_urls' \
43 '(-b --branch=)'{-b,--branch=}':To checkout BRANCH' && ret=0
44 ;;
45 (help)
46 _arguments \
47 '::Repository sub command:(add list update)' && ret=0
48 ;;
49 (update)
50 _arguments \
51 ":Update the repository named NAME:($(kameleon repository list))" && ret=0
52 ;;
53 esac
54 esac
55 return ret
56 }
57
58 # Template kameleon subcommands
59 _kameleon_template () {
60 local curcontext=$curcontext state line ret=1
61 declare -A opt_args
62
63 _arguments -C \
64 ': :->command' \
65 '*:: :->option-or-argument' && ret=0
66
67 case $state in
68 (command)
69 declare -a commands
70
71 commands=(
72 help:'Describe available subcommands or one specific subcommand'
73 import:'Imports the given template'
74 info:'Display detailed information about a template'
75 list:'Lists available templates'
76 repository:'alias for \"kameleon repository\"')
77
78 _describe -t commands command commands && ret=0
79 ;;
80 (option-or-argument)
81 curcontext=${curcontext%:*}-$line[1]:
82
83 case $line[1] in
84 (help)
85 _arguments \
86 '::Template sub command:(import info list repository)' && ret=0
87 ;;
88 (import)
89 _arguments \
90 ":template name:($(kameleon template list | tail -n +4 | cut -f1 -d'|'))" && ret=0
91 ;;
92 (info)
93 _arguments \
94 ":template name:($(kameleon template list | tail -n +4 | cut -f1 -d'|'))" && ret=0
95 '*'{-g,--global}':Custom global variable define as key\:value' && ret=0
96 ;;
97 (repository)
98 _kameleon_repository && ret=0
99 ;;
100 esac
101 esac
102 return ret
103 }
104 # TODO:
105 # - add checkpoint list completion
106 # - add key completion for global
107 # - factorize some options
108 # - allow common options everywere (not just befor command)
109
110 _kameleon () {
111 local curcontext=$curcontext state line ret=1
112 declare -A opt_args
113
114 _arguments -C \
115 '(--no-color)--color[Enables colorization in output (Default)]' \
116 '(--color)--no-color[Disables colorization in output]' \
117 '(--no-verbose --debug)--verbose[Enables verbose output for kameleon Users]' \
118 '(--verbose)--no-verbose[Disables verbose output for kameleon Users (Default)]' \
119 '(--no-debug)--debug[Enables debug output for kameleon Developpers]' \
120 '(--debug --verbose)--no-debug[Disables debug output for kameleon Users and Developpers(Default)]' \
121 '(--no-script)--script[Never prompts for User intervention]' \
122 '(--script)--no-script[Prompts for user intervention if necessary (Default)]' \
123 ': :->command' \
124 '*:: :->option-or-argument' && ret=0
125
126 case $state in
127 (command)
128 declare -a commands
129
130 commands=(
131 build:'Builds the appliance from the given recipe'
132 help:'Describe available commands or one specific command'
133 info:'Display detailed information about a recipe'
134 list:'Lists all defined recipes in the current directory'
135 new:'Creates a new recipe'
136 repository:'Manages set of remote git repositories'
137 template:'Lists and imports templates'
138 version:'Prints the Kameleon version information')
139
140 _describe -t commands command commands && ret=0
141 ;;
142 (option-or-argument)
143 curcontext=${curcontext%:*}-$line[1]:
144
145 case $line[1] in
146 (build)
147 _arguments -C \
148 '(--from-cache)1:Kameleon recipe path:_files' \
149 '(1)--from-cache=:Persistent cache tar file to build the image:_files' \
150 '--cache-archive-compression=:Select the persistent cache compression:(gzip xz bz2)' \
151 '(-b --build-path)'{-b,--build-path=}':Build directory path:_directories' \
152 '--clean[Runs the command `kameleon clean` first]' \
153 '--from-checkpoint=:Specify checkpoint to build the image' \
154 '--enable-checkpoint[Enables checkpoint \[experimental\]]' \
155 {--checkpoints,--list-checkpoints}'[Lists all availables checkpoints]' \
156 '--enable-cache[Generates a persistent cache for the appliance]' \
157 '--cache-path=:Cache directory path:_directories' \
158 '--proxy=:Specifies the hostname and port number of the parent HTTP proxy define as host\:port' \
159 '--proxy-credentials=:Specifies the username and password if the parent proxy requires authorisation define as username\:password' \
160 '*'{-g,--global}':Custom global variable define as key\:value' && ret=0
161 ;;
162 (help)
163 _arguments \
164 ":Kameleon commands:($(kameleon commands))" && ret=0
165 ;;
166 (info)
167 _arguments \
168 '*'{-g,--global}':Custom global variable define as key\:value' \
169 '(--from-cache)1:Kameleon recipe path:_files' \
170 '(1)--from-cache=:Persistent cache tar file to get info from:_files' && ret=0
171 ;;
172 (list)
173 _nothing
174 ;;
175 (new)
176 _arguments \
177 '1:Kameleon recipe path:_files' \
178 '2:Template name:->template_name' && ret=0
179 case "$state" in
180 template_name)
181 _alternative ":templates name:($(kameleon template list | tail -n +4 | cut -f1 -d'|'))" && ret=0
182 ;;
183 esac
184 ;;
185 (repository)
186 _kameleon_repository && ret=0
187 ;;
188 (template)
189 _kameleon_template && ret=0
190 ;;
191 (*)
192 _nothing
193 ;;
194 esac
195 ;;
196 esac
197
198 return ret
199 }
200
201 _kameleon "$@"