|
1 | | -#!/bin/bash |
2 | | - |
| 1 | +_mistral_opts="" # lazy init |
| 2 | +_mistral_flags="" # lazy init |
| 3 | +_mistral_opts_exp="" # lazy init |
3 | 4 | _mistral() |
4 | 5 | { |
5 | | - declare -A SUBCOMMANDS |
6 | | - declare -A OPTS |
7 | | - |
8 | | - OPTS["action-execution-get"]="-h --help -f --format -c --column --max-width --prefix" |
9 | | - OPTS["action-execution-get-input"]="-h --help" |
10 | | - OPTS["action-execution-get-output"]="-h --help" |
11 | | - OPTS["action-execution-list"]="-h --help -f --format -c --column --max-width --quote" |
12 | | - OPTS["action-execution-update"]="-h --help -f --format -c --column --max-width --prefix --state --output" |
13 | | - OPTS["action-create"]="-h --help -f --format -c --column --max-width --quote" |
14 | | - OPTS["action-delete"]="-h --help" |
15 | | - OPTS["action-get"]="-h --help -f --format -c --column --max-width --variable --prefix" |
16 | | - OPTS["action-get-definition"]="-h --help" |
17 | | - OPTS["action-list"]="-h --help -f --format -c --column --max-width --quote" |
18 | | - OPTS["action-update"]="-h --help -f --format -c --column --max-width --quote" |
19 | | - OPTS["complete"]="-h --help --name --shell" |
20 | | - OPTS["cron-trigger-create"]="-h --help -f --format -c --column --max-width --variable --prefix" |
21 | | - OPTS["cron-trigger-delete"]="-h --help" |
22 | | - OPTS["cron-trigger-get"]="-h --help -f --format -c --column --max-width --variable --prefix" |
23 | | - OPTS["cron-trigger-list"]="-h --help -f --format -c --column --max-width --quote" |
24 | | - OPTS["environment-create"]="-h --help -f --format -c --column --max-width --variable --prefix" |
25 | | - OPTS["environment-delete"]="-h --help" |
26 | | - OPTS["environment-get"]="-h --help -f --format -c --column --max-width --variable --prefix" |
27 | | - OPTS["environment-list"]="-h --help -f --format -c --column --max-width --quote" |
28 | | - OPTS["environment-update"]="-h --help -f --format -c --column --max-width --variable --prefix" |
29 | | - OPTS["execution-create"]="-h --help -f --format -c --column --max-width --variable --prefix" |
30 | | - OPTS["execution-delete"]="-h --help" |
31 | | - OPTS["execution-get"]="-h --help -f --format -c --column --max-width --variable --prefix" |
32 | | - OPTS["execution-get-input"]="-h --help" |
33 | | - OPTS["execution-get-output"]="-h --help" |
34 | | - OPTS["execution-list"]="-h --help -f --format -c --column --max-width --quote" |
35 | | - OPTS["execution-update"]="-h --help -f --format -c --column --max-width --variable --prefix" |
36 | | - OPTS["help"]="-h --help" |
37 | | - OPTS["task-get"]="-h --help -f --format -c --column --max-width --variable --prefix" |
38 | | - OPTS["task-get-result"]="-h --help" |
39 | | - OPTS["task-get-published"]="-h --help -f --format -c --column --max-width --variable --prefix" |
40 | | - OPTS["task-list"]="-h --help -f --format -c --column --max-width --quote" |
41 | | - OPTS["workbook-create"]="-h --help -f --format -c --column --max-width --variable --prefix" |
42 | | - OPTS["workbook-delete"]="-h --help" |
43 | | - OPTS["workbook-get"]="-h --help -f --format -c --column --max-width --variable --prefix" |
44 | | - OPTS["workbook-get-definition"]="-h --help" |
45 | | - OPTS["workbook-list"]="-h --help -f --format -c --column --max-width --quote" |
46 | | - OPTS["workbook-update"]="-h --help -f --format -c --column --max-width --variable --prefix" |
47 | | - OPTS["workbook-validate"]="-h --help -f --format -c --column --max-width --prefix" |
48 | | - OPTS["workflow-create"]="-h --help -f --format -c --column --max-width --quote" |
49 | | - OPTS["workflow-delete"]="-h --help" |
50 | | - OPTS["workflow-get"]="-h --help -f --format -c --column --max-width --variable --prefix" |
51 | | - OPTS["workflow-get-definition"]="-h --help" |
52 | | - OPTS["workflow-list"]="-h --help -f --format -c --column --max-width --quote" |
53 | | - OPTS["workflow-update"]="-h --help -f --format -c --column --max-width --quote" |
54 | | - OPTS["workflow-validate"]="-h --help -f --format -c --column --max-width --prefix" |
55 | | - |
56 | | - COMMANDS="${!OPTS[*]}" |
57 | | - COMPREPLY=() |
| 6 | + local cur prev mbc cflags |
| 7 | + COMPREPLY=() |
| 8 | + cur="${COMP_WORDS[COMP_CWORD]}" |
| 9 | + prev="${COMP_WORDS[COMP_CWORD-1]}" |
58 | 10 |
|
59 | | - local cur="${COMP_WORDS[COMP_CWORD]}" |
60 | | - local prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 11 | + if [ "x$_mistral_opts" == "x" ] ; then |
| 12 | + mbc="`mistral bash-completion`" |
| 13 | + _mistral_opts="`echo "$mbc" | sed -e "s/\s-[a-z0-9_-]*//g" -e "s/\s\s*/ /g"`" |
| 14 | + _mistral_flags="`echo " $mbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/\s\s*/ /g"`" |
| 15 | + _mistral_opts_exp="`echo "$_mistral_opts" | sed -e "s/\s/|/g"`" |
| 16 | + fi |
61 | 17 |
|
62 | | - if [[ $cur =~ (\.|\~|\/).* ]] ; then |
63 | | - _filedir |
64 | | - elif [ $COMP_CWORD == "1" ] ; then |
65 | | - COMPREPLY=($(compgen -W "$COMMANDS" -- ${cur})) |
66 | | - elif [ $COMP_CWORD == "2" ] ; then |
67 | | - COMPREPLY=($(compgen -W "${OPTS[${prev}]}" -- ${cur})) |
68 | | - fi |
69 | | - return 0 |
| 18 | + if [[ " ${COMP_WORDS[@]} " =~ " "($_mistral_opts_exp)" " && "$prev" != "help" ]] ; then |
| 19 | + COMPREPLY=($(compgen -W "${_mistral_flags}" -- ${cur})) |
| 20 | + else |
| 21 | + COMPREPLY=($(compgen -W "${_mistral_opts}" -- ${cur})) |
| 22 | + fi |
| 23 | + return 0 |
70 | 24 | } |
71 | 25 | complete -F _mistral mistral |
0 commit comments