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