| 192 |
- |
1 |
# bash completion for composer-cli
|
|
|
2 |
|
|
|
3 |
__composer_cli_flags="-h --help -j --json -s --socket --log -a --api --test -V"
|
|
|
4 |
|
|
|
5 |
declare -A __composer_cli_cmds=(
|
|
|
6 |
[compose]="list start start-ostree types status log cancel delete info metadata logs results image"
|
|
|
7 |
[blueprints]="list show changes diff save delete depsolve push freeze tag undo workspace"
|
|
|
8 |
[modules]="list"
|
|
|
9 |
[projects]="list info"
|
|
|
10 |
[sources]="list info add change delete"
|
|
|
11 |
[help]=""
|
|
|
12 |
)
|
|
|
13 |
|
|
|
14 |
__composer_socket_ok() {
|
|
|
15 |
[ -w "${COMPOSER_SOCKET:-/run/weldr/api.socket}" ]
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
__composer_blueprints() {
|
|
|
19 |
__composer_socket_ok && composer-cli blueprints list
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
__composer_sources() {
|
|
|
23 |
__composer_socket_ok && composer-cli sources list
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
__composer_compose_types() {
|
|
|
27 |
__composer_socket_ok && composer-cli compose types
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
__composer_composes() {
|
|
|
31 |
__composer_socket_ok && composer-cli compose list $@ | while read id rest; do echo $id; done
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
__word_in_list() {
|
|
|
35 |
local w word=$1; shift
|
|
|
36 |
for w in "$@"; do
|
|
|
37 |
[ "$w" == "$word" ] && return 0
|
|
|
38 |
done
|
|
|
39 |
return 1
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
_composer_cli() {
|
|
|
43 |
local cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
44 |
local w="" wi=0 cmd="__NONE__" subcmd="__NONE__" cmd_cword=0
|
|
|
45 |
|
|
|
46 |
# find the command and its subcommand
|
|
|
47 |
for (( wi=0; wi < ${#COMP_WORDS[*]}; wi++ )); do
|
|
|
48 |
if __word_in_list "${COMP_WORDS[wi]}" "${!__composer_cli_cmds[@]}"; then
|
|
|
49 |
cmd="${COMP_WORDS[wi]}"
|
|
|
50 |
subcmd="${COMP_WORDS[wi+1]}"
|
|
|
51 |
cmd_cword=$((COMP_CWORD-wi))
|
|
|
52 |
break
|
|
|
53 |
fi
|
|
|
54 |
done
|
|
|
55 |
|
|
|
56 |
COMPREPLY=()
|
|
|
57 |
|
|
|
58 |
if [ "$cmd_cword" -le 0 ]; then
|
|
|
59 |
# No command yet, complete flags or commands
|
|
|
60 |
case "$prev" in
|
|
|
61 |
-s|--socket|--log)
|
|
|
62 |
# If it's a flag that takes a filename, suggest filenames
|
|
|
63 |
compopt -o filenames
|
|
|
64 |
COMPREPLY=($(compgen -f -- "${cur}"))
|
|
|
65 |
;;
|
|
|
66 |
-a|--api|--test)
|
|
|
67 |
# If it's a flag that takes an arg we can't guess, don't suggest anything
|
|
|
68 |
COMPREPLY=()
|
|
|
69 |
;;
|
|
|
70 |
*)
|
|
|
71 |
if [ "${cur:0:1}" == "-" ]; then
|
|
|
72 |
# Suggest flags if cur starts with '-'
|
|
|
73 |
COMPREPLY=($(compgen -W "${__composer_cli_flags}" -- "${cur}"))
|
|
|
74 |
else
|
|
|
75 |
# Suggest commands if there isn't one already
|
|
|
76 |
COMPREPLY=($(compgen -W "${!__composer_cli_cmds[*]}" -- "${cur}"))
|
|
|
77 |
fi
|
|
|
78 |
;;
|
|
|
79 |
esac
|
|
|
80 |
elif [ $cmd_cword == 1 ]; then
|
|
|
81 |
# Complete the word after the command
|
|
|
82 |
COMPREPLY=($(compgen -W "${__composer_cli_cmds[$cmd]} help" -- "${cur}"))
|
|
|
83 |
elif [ $cmd_cword == 2 ]; then
|
|
|
84 |
# Complete word(s) after subcommand
|
|
|
85 |
case "$cmd:$subcmd" in
|
|
|
86 |
compose:list)
|
|
|
87 |
COMPREPLY=($(compgen -W "waiting running finish failed" -- "${cur}"))
|
|
|
88 |
;;
|
|
|
89 |
*:list|*:help|compose:types)
|
|
|
90 |
COMPREPLY=()
|
|
|
91 |
;;
|
|
|
92 |
sources:info|sources:delete)
|
|
|
93 |
COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}"))
|
|
|
94 |
;;
|
|
|
95 |
sources:add|sources:change|blueprints:workspace|blueprints:push)
|
|
|
96 |
compopt -o filenames
|
|
|
97 |
COMPREPLY=($(compgen -f -- "${cur}"))
|
|
|
98 |
;;
|
|
|
99 |
blueprints:freeze)
|
|
|
100 |
COMPREPLY=($(compgen -W "$(__composer_blueprints) show save" -- "${cur}"))
|
|
|
101 |
;;
|
|
|
102 |
compose:start|compose:start-ostree|blueprints:*)
|
|
|
103 |
COMPREPLY=($(compgen -W "$(__composer_blueprints)" -- "${cur}"))
|
|
|
104 |
;;
|
|
|
105 |
compose:cancel)
|
|
|
106 |
COMPREPLY=($(compgen -W "$(__composer_composes running waiting)" -- "${cur}"))
|
|
|
107 |
;;
|
|
|
108 |
compose:delete|compose:results|compose:metadata)
|
|
|
109 |
COMPREPLY=($(compgen -W "$(__composer_composes finished failed)" -- "${cur}"))
|
|
|
110 |
;;
|
|
|
111 |
compose:log*)
|
|
|
112 |
COMPREPLY=($(compgen -W "$(__composer_composes running finished failed)" -- "${cur}"))
|
|
|
113 |
;;
|
|
|
114 |
compose:image)
|
|
|
115 |
COMPREPLY=($(compgen -W "$(__composer_composes finished)" -- "${cur}"))
|
|
|
116 |
;;
|
|
|
117 |
compose:*)
|
|
|
118 |
COMPREPLY=($(compgen -W "$(__composer_composes)" -- "${cur}"))
|
|
|
119 |
;;
|
|
|
120 |
esac
|
|
|
121 |
else
|
|
|
122 |
# Complete words past the subcommand's argument (if appropriate)
|
|
|
123 |
case "$cmd:$subcmd" in
|
|
|
124 |
compose:delete)
|
|
|
125 |
COMPREPLY=($(compgen -W "$(__composer_composes finished failed)" -- "${cur}"))
|
|
|
126 |
;;
|
|
|
127 |
compose:start|compose:start-ostree)
|
|
|
128 |
subpos="$subcmd:$cmd_cword"
|
|
|
129 |
if [ "$cmd_cword" == 3 ]; then
|
|
|
130 |
COMPREPLY=($(compgen -W "$(__composer_compose_types)" -- "${cur}"))
|
|
|
131 |
elif [ "$subpos" == "start:5" ] || [ "$subpos" == "start-ostree:7" ]; then
|
|
|
132 |
# If they have typed something looking like a path, use file completion
|
|
|
133 |
# otherwise suggest providers.
|
|
|
134 |
case "${cur}" in
|
|
|
135 |
*/*)
|
|
|
136 |
compopt -o filenames
|
|
|
137 |
COMPREPLY=($(compgen -f -- "${cur}"))
|
|
|
138 |
;;
|
|
|
139 |
*)
|
|
|
140 |
COMPREPLY=($(compgen -W "$(__composer_provider_list)" -- "${cur}"))
|
|
|
141 |
;;
|
|
|
142 |
esac
|
|
|
143 |
elif [ "$subpos" == "start:6" ] || [ "$subpos" == "start-ostree:8" ]; then
|
|
|
144 |
COMPREPLY=($(compgen -W "$(__composer_profile_list ${prev})" -- "${cur}"))
|
|
|
145 |
fi
|
|
|
146 |
;;
|
|
|
147 |
# TODO: blueprints:diff and blueprints:undo want commits
|
|
|
148 |
blueprints:freeze|blueprints:save|blueprints:depsolve|blueprints:changes|blueprints:show)
|
|
|
149 |
COMPREPLY=($(compgen -W "$(__composer_blueprints)" -- "${cur}"))
|
|
|
150 |
;;
|
|
|
151 |
sources:info)
|
|
|
152 |
COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}"))
|
|
|
153 |
;;
|
|
|
154 |
esac
|
|
|
155 |
fi
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
complete -F _composer_cli composer-cli
|