diff options
Diffstat (limited to 'meta-openstack/recipes-support/salt/files/salt-common.bash_completion')
| -rw-r--r-- | meta-openstack/recipes-support/salt/files/salt-common.bash_completion | 332 |
1 files changed, 332 insertions, 0 deletions
diff --git a/meta-openstack/recipes-support/salt/files/salt-common.bash_completion b/meta-openstack/recipes-support/salt/files/salt-common.bash_completion new file mode 100644 index 0000000..a457f4d --- /dev/null +++ b/meta-openstack/recipes-support/salt/files/salt-common.bash_completion | |||
| @@ -0,0 +1,332 @@ | |||
| 1 | # written by David Pravec | ||
| 2 | # - feel free to /msg alekibango on IRC if you want to talk about this file | ||
| 3 | |||
| 4 | # TODO: check if --config|-c was used and use configured config file for queries | ||
| 5 | # TODO: solve somehow completion for salt -G pythonversion:[tab] | ||
| 6 | # (not sure what to do with lists) | ||
| 7 | # TODO: --range[tab] -- how? | ||
| 8 | # TODO: -E --exsel[tab] -- how? | ||
| 9 | # TODO: --compound[tab] -- how? | ||
| 10 | # TODO: use history to extract some words, esp. if ${cur} is empty | ||
| 11 | # TODO: TEST EVERYTING a lot | ||
| 12 | # TODO: cache results of some functions? where? how long? | ||
| 13 | # TODO: is it ok to use '--timeout 2' ? | ||
| 14 | |||
| 15 | |||
| 16 | _salt_get_grains(){ | ||
| 17 | if [ "$1" = 'local' ] ; then | ||
| 18 | salt-call --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g' | ||
| 19 | else | ||
| 20 | salt '*' --timeout 2 --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g' | ||
| 21 | fi | ||
| 22 | } | ||
| 23 | |||
| 24 | _salt_get_grain_values(){ | ||
| 25 | if [ "$1" = 'local' ] ; then | ||
| 26 | salt-call --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$' | ||
| 27 | else | ||
| 28 | salt '*' --timeout 2 --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$' | ||
| 29 | fi | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | _salt(){ | ||
| 34 | local cur prev opts _salt_grains _salt_coms pprev ppprev | ||
| 35 | COMPREPLY=() | ||
| 36 | cur="${COMP_WORDS[COMP_CWORD]}" | ||
| 37 | prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
| 38 | if [ ${COMP_CWORD} -gt 2 ]; then | ||
| 39 | pprev="${COMP_WORDS[COMP_CWORD-2]}" | ||
| 40 | fi | ||
| 41 | if [ ${COMP_CWORD} -gt 3 ]; then | ||
| 42 | ppprev="${COMP_WORDS[COMP_CWORD-3]}" | ||
| 43 | fi | ||
| 44 | |||
| 45 | opts="-h --help -d --doc --documentation --version --versions-report -c \ | ||
| 46 | --config-dir= -v --verbose -t --timeout= -s --static -b --batch= \ | ||
| 47 | --batch-size= -E --pcre -L --list -G --grain --grain-pcre -N \ | ||
| 48 | --nodegroup -R --range -C --compound -X --exsel -I --pillar \ | ||
| 49 | --return= -a --auth= --eauth= --extended-auth= -T --make-token -S \ | ||
| 50 | --ipcidr --out=pprint --out=yaml --out=overstatestage --out=json \ | ||
| 51 | --out=raw --out=highstate --out=key --out=txt --no-color --out-indent= " | ||
| 52 | |||
| 53 | if [[ "${cur}" == -* ]] ; then | ||
| 54 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
| 55 | return 0 | ||
| 56 | fi | ||
| 57 | |||
| 58 | # 2 special cases for filling up grain values | ||
| 59 | case "${pprev}" in | ||
| 60 | -G|--grain|--grain-pcre) | ||
| 61 | if [ "${cur}" = ":" ]; then | ||
| 62 | COMPREPLY=($(compgen -W "`_salt_get_grain_values ${prev}`" )) | ||
| 63 | return 0 | ||
| 64 | fi | ||
| 65 | ;; | ||
| 66 | esac | ||
| 67 | case "${ppprev}" in | ||
| 68 | -G|--grain|--grain-pcre) | ||
| 69 | if [ "${prev}" = ":" ]; then | ||
| 70 | COMPREPLY=( $(compgen -W "`_salt_get_grain_values ${pprev}`" -- ${cur}) ) | ||
| 71 | return 0 | ||
| 72 | fi | ||
| 73 | ;; | ||
| 74 | esac | ||
| 75 | |||
| 76 | if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then | ||
| 77 | cur="" | ||
| 78 | fi | ||
| 79 | if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then | ||
| 80 | prev="${pprev}" | ||
| 81 | fi | ||
| 82 | |||
| 83 | case "${prev}" in | ||
| 84 | |||
| 85 | -c|--config) | ||
| 86 | COMPREPLY=($(compgen -f -- ${cur})) | ||
| 87 | return 0 | ||
| 88 | ;; | ||
| 89 | salt) | ||
| 90 | COMPREPLY=($(compgen -W "\'*\' ${opts} `salt-key --no-color -l acc`" -- ${cur})) | ||
| 91 | return 0 | ||
| 92 | ;; | ||
| 93 | -E|--pcre) | ||
| 94 | COMPREPLY=($(compgen -W "`salt-key --no-color -l acc`" -- ${cur})) | ||
| 95 | return 0 | ||
| 96 | ;; | ||
| 97 | -G|--grain|--grain-pcre) | ||
| 98 | COMPREPLY=($(compgen -W "$(_salt_get_grains)" -- ${cur})) | ||
| 99 | return 0 | ||
| 100 | ;; | ||
| 101 | -C|--compound) | ||
| 102 | COMPREPLY=() # TODO: finish this one? how? | ||
| 103 | return 0 | ||
| 104 | ;; | ||
| 105 | -t|--timeout) | ||
| 106 | COMPREPLY=($( compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 60 90 120 180" -- ${cur})) | ||
| 107 | return 0 | ||
| 108 | ;; | ||
| 109 | -b|--batch|--batch-size) | ||
| 110 | COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 50 60 70 80 90 100 120 150 200")) | ||
| 111 | return 0 | ||
| 112 | ;; | ||
| 113 | -X|--exsel) # TODO: finish this one? how? | ||
| 114 | return 0 | ||
| 115 | ;; | ||
| 116 | -N|--nodegroup) | ||
| 117 | MASTER_CONFIG='/etc/salt/master' | ||
| 118 | COMPREPLY=($(compgen -W "`awk -F ':' 'BEGIN {print_line = 0}; /^nodegroups/ {print_line = 1;getline } print_line && /^ */ {print $1} /^[^ ]/ {print_line = 0}' <${MASTER_CONFIG}`" -- ${cur})) | ||
| 119 | return 0 | ||
| 120 | ;; | ||
| 121 | esac | ||
| 122 | |||
| 123 | _salt_coms="$(salt '*' --timeout 2 --out=txt -- sys.list_functions | sed 's/^.*\[//' | tr -d ",']" )" | ||
| 124 | all="${opts} ${_salt_coms}" | ||
| 125 | COMPREPLY=( $(compgen -W "${all}" -- ${cur}) ) | ||
| 126 | |||
| 127 | return 0 | ||
| 128 | } | ||
| 129 | |||
| 130 | complete -F _salt salt | ||
| 131 | |||
| 132 | |||
| 133 | _saltkey(){ | ||
| 134 | local cur prev opts prev pprev | ||
| 135 | COMPREPLY=() | ||
| 136 | cur="${COMP_WORDS[COMP_CWORD]}" | ||
| 137 | prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
| 138 | opts="-c --config-dir= -h --help --version --versions-report -q --quiet \ | ||
| 139 | -y --yes --gen-keys= --gen-keys-dir= --keysize= --key-logfile= \ | ||
| 140 | -l --list= -L --list-all -a --accept= -A --accept-all \ | ||
| 141 | -r --reject= -R --reject-all -p --print= -P --print-all \ | ||
| 142 | -d --delete= -D --delete-all -f --finger= -F --finger-all \ | ||
| 143 | --out=pprint --out=yaml --out=overstatestage --out=json --out=raw \ | ||
| 144 | --out=highstate --out=key --out=txt --no-color --out-indent= " | ||
| 145 | if [ ${COMP_CWORD} -gt 2 ]; then | ||
| 146 | pprev="${COMP_WORDS[COMP_CWORD-2]}" | ||
| 147 | fi | ||
| 148 | if [ ${COMP_CWORD} -gt 3 ]; then | ||
| 149 | ppprev="${COMP_WORDS[COMP_CWORD-3]}" | ||
| 150 | fi | ||
| 151 | if [[ "${cur}" == -* ]] ; then | ||
| 152 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
| 153 | return 0 | ||
| 154 | fi | ||
| 155 | |||
| 156 | if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then | ||
| 157 | cur="" | ||
| 158 | fi | ||
| 159 | if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then | ||
| 160 | prev="${pprev}" | ||
| 161 | fi | ||
| 162 | |||
| 163 | case "${prev}" in | ||
| 164 | -a|--accept) | ||
| 165 | COMPREPLY=($(compgen -W "$(salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur})) | ||
| 166 | return 0 | ||
| 167 | ;; | ||
| 168 | -r|--reject) | ||
| 169 | COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color)" -- ${cur})) | ||
| 170 | return 0 | ||
| 171 | ;; | ||
| 172 | -d|--delete) | ||
| 173 | COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur})) | ||
| 174 | return 0 | ||
| 175 | ;; | ||
| 176 | -c|--config) | ||
| 177 | COMPREPLY=($(compgen -f -- ${cur})) | ||
| 178 | return 0 | ||
| 179 | ;; | ||
| 180 | --keysize) | ||
| 181 | COMPREPLY=($(compgen -W "2048 3072 4096 5120 6144" -- ${cur})) | ||
| 182 | return 0 | ||
| 183 | ;; | ||
| 184 | --gen-keys) | ||
| 185 | return 0 | ||
| 186 | ;; | ||
| 187 | --gen-keys-dir) | ||
| 188 | COMPREPLY=($(compgen -d -- ${cur})) | ||
| 189 | return 0 | ||
| 190 | ;; | ||
| 191 | -p|--print) | ||
| 192 | COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur})) | ||
| 193 | return 0 | ||
| 194 | ;; | ||
| 195 | -l|--list) | ||
| 196 | COMPREPLY=($(compgen -W "pre un acc accepted unaccepted rej rejected all" -- ${cur})) | ||
| 197 | return 0 | ||
| 198 | ;; | ||
| 199 | --accept-all) | ||
| 200 | return 0 | ||
| 201 | ;; | ||
| 202 | esac | ||
| 203 | COMPREPLY=($(compgen -W "${opts} " -- ${cur})) | ||
| 204 | return 0 | ||
| 205 | } | ||
| 206 | |||
| 207 | complete -F _saltkey salt-key | ||
| 208 | |||
| 209 | _saltcall(){ | ||
| 210 | local cur prev opts _salt_coms pprev ppprev | ||
| 211 | COMPREPLY=() | ||
| 212 | cur="${COMP_WORDS[COMP_CWORD]}" | ||
| 213 | prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
| 214 | opts="-h --help -d --doc --documentation --version --versions-report \ | ||
| 215 | -m --module-dirs= -g --grains --return= --local -c --config-dir= -l --log-level= \ | ||
| 216 | --out=pprint --out=yaml --out=overstatestage --out=json --out=raw \ | ||
| 217 | --out=highstate --out=key --out=txt --no-color --out-indent= " | ||
| 218 | if [ ${COMP_CWORD} -gt 2 ]; then | ||
| 219 | pprev="${COMP_WORDS[COMP_CWORD-2]}" | ||
| 220 | fi | ||
| 221 | if [ ${COMP_CWORD} -gt 3 ]; then | ||
| 222 | ppprev="${COMP_WORDS[COMP_CWORD-3]}" | ||
| 223 | fi | ||
| 224 | if [[ "${cur}" == -* ]] ; then | ||
| 225 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
| 226 | return 0 | ||
| 227 | fi | ||
| 228 | |||
| 229 | if [ "${cur}" = "=" ] && [[ ${prev} == --* ]]; then | ||
| 230 | cur="" | ||
| 231 | fi | ||
| 232 | if [ "${prev}" = "=" ] && [[ ${pprev} == --* ]]; then | ||
| 233 | prev="${pprev}" | ||
| 234 | fi | ||
| 235 | |||
| 236 | case ${prev} in | ||
| 237 | -m|--module-dirs) | ||
| 238 | COMPREPLY=( $(compgen -d ${cur} )) | ||
| 239 | return 0 | ||
| 240 | ;; | ||
| 241 | -l|--log-level) | ||
| 242 | COMPREPLY=( $(compgen -W "info none garbage trace warning error debug" -- ${cur})) | ||
| 243 | return 0 | ||
| 244 | ;; | ||
| 245 | -g|grains) | ||
| 246 | return 0 | ||
| 247 | ;; | ||
| 248 | salt-call) | ||
| 249 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
| 250 | return 0 | ||
| 251 | ;; | ||
| 252 | esac | ||
| 253 | |||
| 254 | _salt_coms="$(salt-call --out=txt -- sys.list_functions|sed 's/^.*\[//' | tr -d ",']" )" | ||
| 255 | COMPREPLY=( $(compgen -W "${opts} ${_salt_coms}" -- ${cur} )) | ||
| 256 | return 0 | ||
| 257 | } | ||
| 258 | |||
| 259 | complete -F _saltcall salt-call | ||
| 260 | |||
| 261 | |||
| 262 | _saltcp(){ | ||
| 263 | local cur prev opts target prefpart postpart helper filt pprev ppprev | ||
| 264 | COMPREPLY=() | ||
| 265 | cur="${COMP_WORDS[COMP_CWORD]}" | ||
| 266 | prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
| 267 | opts="-t --timeout= -s --static -b --batch= --batch-size= \ | ||
| 268 | -h --help --version --versions-report -c --config-dir= \ | ||
| 269 | -E --pcre -L --list -G --grain --grain-pcre -N --nodegroup \ | ||
| 270 | -R --range -C --compound -X --exsel -I --pillar \ | ||
| 271 | --out=pprint --out=yaml --out=overstatestage --out=json --out=raw \ | ||
| 272 | --out=highstate --out=key --out=txt --no-color --out-indent= " | ||
| 273 | if [[ "${cur}" == -* ]] ; then | ||
| 274 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
| 275 | return 0 | ||
| 276 | fi | ||
| 277 | |||
| 278 | if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then | ||
| 279 | cur="" | ||
| 280 | fi | ||
| 281 | if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then | ||
| 282 | prev=${pprev} | ||
| 283 | fi | ||
| 284 | |||
| 285 | case ${prev} in | ||
| 286 | salt-cp) | ||
| 287 | COMPREPLY=($(compgen -W "${opts} `salt-key -l acc --no-color`" -- ${cur})) | ||
| 288 | return 0 | ||
| 289 | ;; | ||
| 290 | -t|--timeout) | ||
| 291 | # those numbers are just a hint | ||
| 292 | COMPREPLY=($(compgen -W "2 3 4 8 10 15 20 25 30 40 60 90 120 180 240 300" -- ${cur} )) | ||
| 293 | return 0 | ||
| 294 | ;; | ||
| 295 | -E|--pcre) | ||
| 296 | COMPREPLY=($(compgen -W "`salt-key -l acc --no-color`" -- ${cur})) | ||
| 297 | return 0 | ||
| 298 | ;; | ||
| 299 | -L|--list) | ||
| 300 | # IMPROVEMENTS ARE WELCOME | ||
| 301 | prefpart="${cur%,*}," | ||
| 302 | postpart=${cur##*,} | ||
| 303 | filt="^\($(echo ${cur}| sed 's:,:\\|:g')\)$" | ||
| 304 | helper=($(salt-key -l acc --no-color | grep -v "${filt}" | sed "s/^/${prefpart}/")) | ||
| 305 | COMPREPLY=($(compgen -W "${helper[*]}" -- ${cur})) | ||
| 306 | |||
| 307 | return 0 | ||
| 308 | ;; | ||
| 309 | -G|--grain|--grain-pcre) | ||
| 310 | COMPREPLY=($(compgen -W "$(_salt_get_grains)" -- ${cur})) | ||
| 311 | return 0 | ||
| 312 | ;; | ||
| 313 | # FIXME | ||
| 314 | -R|--range) | ||
| 315 | # FIXME ?? | ||
| 316 | return 0 | ||
| 317 | ;; | ||
| 318 | -C|--compound) | ||
| 319 | # FIXME ?? | ||
| 320 | return 0 | ||
| 321 | ;; | ||
| 322 | -c|--config) | ||
| 323 | COMPREPLY=($(compgen -f -- ${cur})) | ||
| 324 | return 0 | ||
| 325 | ;; | ||
| 326 | esac | ||
| 327 | |||
| 328 | # default is using opts: | ||
| 329 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
| 330 | } | ||
| 331 | |||
| 332 | complete -F _saltcp salt-cp | ||
