Add mic zsh tab completion support
[tools/mic.git] / etc / _mic
1 #compdef mic
2 #
3 # Copyright (c) 2013 Intel, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; version 2 of the License
8
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 # for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc., 59
16 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 _mic() {
19   typeset -A opt_args
20   local context state line curcontext="$curcontext"
21
22   local ret=1
23
24   _arguments -C \
25     {-h,--help}'[show this help message and exit]' \
26     "--version[show program\'s version number and exit]" \
27     {-d,--debug}'[print debug message]' \
28     {-v,--verbose}'[verbose information]' \
29     '1: :_mic_cmds' \
30     '*::arg:->args' \
31   && ret=0
32
33
34   case "$state" in
35     (args)
36       curcontext="${curcontext%:*:*}:mic-cmd-$words[1]:"
37       case $words[1] in
38         (chroot|ch)
39           _arguments \
40             {-h,--help}'[show this help message and exit]' \
41             {-s,--saveto=}'[Save the unpacked image to specified dir]: :_files -/' \
42             '1: :_files -/' \
43               && ret=0
44         ;;
45         (convert|cv)
46           _arguments \
47             {-h,--help}'[show this help message and exit]' \
48             {-S,--shell}'[Launch shell before packaging the converted image]' \
49               && ret=0
50         ;;
51         (create|cr)
52           _arguments -C \
53             {-h,--help}'[show this help message and exit]' \
54             '--logfile=[Path of logfile]:path' \
55             '-c[Specify config file for mic]:file' \
56             '-k[Cache directory to store the downloaded]: :_files -/' \
57             '-o[Output directory]: :_files -/' \
58             '-A[Specify repo architecture]:parameter' \
59             '--release=[Generate a release of RID with all necessary files, when @BUILD_ID@ is contained in kickstart file, it will be replaced by RID]:parameter' \
60             '--record-pkgs=[Record the info of installed packages, multiple values can be specified which joined by \",\", valid values: \"name\", \"content\", \"license\", \"vcs\"]: :_mic_create_filters -s ,' \
61             '--pkgmgr=[Specify backend package manager]:parameter' \
62             '--local-pkgs-path=[Path for local pkgs(rpms) to be installed]:path' \
63             '--runtime=[Specify  runtime mode, avaiable: bootstrap, native]: :(bootstrap native)' \
64             '--pack-to=[Pack the images together into the specified achive, extension supported: .zip, .tar, .tar.gz, .tar.bz2, etc. by default, .tar will be used]:parameter' \
65             '--copy-kernel[Copy kernel files from image /boot directory to the image output directory.]' \
66             '--install-pkgs=[Specify what type of packages to be installed, valid: source, debuginfo, debugsource]: :(source debuginfo debugsource)' \
67             '--check-pkgs=[Check if given packages would be installed, packages should be separated by comma]' \
68             '--tmpfs[Setup tmpdir as tmpfs to accelerate, experimental feature, use it if you have more than 4G memory]' \
69             '1: :_mic_create_entities' \
70             '*::create-arg:->create-args' \
71               && ret=0
72           case "$state" in
73             (create-args)
74               local -a common_ops
75               common_ops=(
76                 '1:: :(`ls`)' \
77                 {-h,--help}'[show this help message and exit]' \
78                 '--logfile=[Path of logfile]:path' \
79                 '-c[Specify config file for mic]:file' \
80                 '-k[Cache directory to store the downloaded]: :_files -/' \
81                 '-o[Output directory]: :_files -/' \
82                 '-A[Specify repo architecture]:parameter' \
83                 '--release=[Generate a release of RID with all necessary files, when @BUILD_ID@ is contained in kickstart file, it will be replaced by RID]:parameter' \
84                 '--record-pkgs=[Record the info of installed packages, multiple values can be specified which joined by \",\", valid values: \"name\", \"content\", \"license\", \"vcs\"]: :_mic_create_filters -s ,' \
85                 '--pkgmgr=[Specify backend package manager]:parameter' \
86                 '--local-pkgs-path=[Path for local pkgs(rpms) to be installed]:path' \
87                 '--runtime=[Specify  runtime mode, avaiable: bootstrap, native]: :(bootstrap native)' \
88                 '--pack-to=[Pack the images together into the specified achive, extension supported: .zip, .tar, .tar.gz, .tar.bz2, etc. by default, .tar will be used]:parameter' \
89                 '--copy-kernel[Copy kernel files from image /boot directory to the image output directory.]' \
90                 '--install-pkgs=[Specify what type of packages to be installed, valid: source, debuginfo, debugsource]: :(source debuginfo debugsource)' \
91                 '--check-pkgs=[Check if given packages would be installed, packages should be separated by comma]' \
92                 '--tmpfs[Setup tmpdir as tmpfs to accelerate, experimental feature, use it if you have more than 4G memory]' \
93               )
94               case $words[1] in
95                 (auto)
96                   _arguments \
97                     $common_ops \
98                       && ret=0
99                   ;;
100                 (fs)
101                   _arguments \
102                     $common_ops \
103                     '--include-src[Generate a image with source rpms included]' \
104                     && ret=0
105                   ;;
106                 (livecd)
107                   _arguments \
108                     $common_ops \
109                       && ret=0
110                   ;;
111                 (liveusb)
112                   _arguments \
113                     $common_ops \
114                       && ret=0
115                   ;;
116                 (loop)
117                   _arguments \
118                     $common_ops \
119                     '--shrink[Whether to shrink loop images to minimal size]' \
120                     "--compress-image=[Compress all loop images with \'gz\' or \'bz2\']: :(gz bz2)" \
121                     "--compress-disk-image=[Same with --compress-image]: :(gz bz2)" \
122                       && ret=0
123                   ;;
124                 (raw)
125                   _arguments \
126                     $common_ops \
127                     "--fstab-entry=[Set fstab entry, \'name\' means using device names, \'uuid\' means using filesystem uuid]: :(name uuid)" \
128                     '--generate-bmap[also generate the block map file]' \
129                     '--compress-image=[Compress all raw images before package]: :(gz bz2)' \
130                     '--compress-disk-image=[Same with --compress-image]: :(gz bz2)' \
131                     && ret=0
132                   ;;
133                 (help)
134                   _arguments -C \
135                     '1: :_mic_create_entities' \
136                     && ret=0
137                   ;;
138               esac
139               ;;
140           esac
141          ;;
142          (help)
143            _arguments -C \
144              '1: :_mic_cmds' \
145              && ret=0
146         ;;
147       esac
148     ;;
149   esac
150
151   return ret
152 }
153
154 (( $+functions[_mic_cmds] )) ||
155 _mic_cmds() {
156   local commands; commands=(
157     'chroot:chroot into an image'
158     'convert:convert image format'
159     'create:create an image'
160     'help:give detailed help on a specific sub-command'
161   )
162   _describe -t commands 'command' commands "$@"
163 }
164
165 (( $+functions[_mic_create_entities] )) ||
166 _mic_create_entities() {
167   local entities; entities=(
168     'auto:auto detect image type from magic header'
169     'fs:create fs image'
170     'help:give detailed help on a specific sub-command'
171     'livecd:create livecd image'
172     'liveusb:create liveusb image'
173     'loop:create loop image'
174     'raw:create raw image'
175   )
176   _describe -t entities 'entity' entities "$@"
177 }
178
179 (( $+functions[_mic_create_filters] )) ||
180 _mic_create_filters() {
181   local filters; filters=(name content license vcs)
182   _values $@ 'filter' "${filters[@]}"
183 }
184
185 _mic "$@"
186
187 # vim: ft=zsh sw=2 ts=2 et