2018-10-08 16:23:47 +00:00
|
|
|
# bash completion for composer-cli
|
2018-07-31 13:39:38 +00:00
|
|
|
|
|
|
|
__composer_cli_flags="-h --help -j --json -s --socket --log -a --api --test -V"
|
|
|
|
|
|
|
|
declare -A __composer_cli_cmds=(
|
2018-08-07 23:34:03 +00:00
|
|
|
[compose]="list start types status log cancel delete info metadata logs results image"
|
2018-07-31 13:39:38 +00:00
|
|
|
[blueprints]="list show changes diff save delete depsolve push freeze tag undo workspace"
|
|
|
|
[modules]="list"
|
|
|
|
[projects]="list info"
|
|
|
|
[sources]="list info add change delete"
|
2019-09-24 00:03:35 +00:00
|
|
|
[upload]="info start log cancel delete reset"
|
|
|
|
[providers]="list show push save delete"
|
2018-07-31 13:39:38 +00:00
|
|
|
[help]=""
|
|
|
|
)
|
|
|
|
|
|
|
|
__composer_socket_ok() {
|
|
|
|
[ -w "${COMPOSER_SOCKET:-/run/weldr/api.socket}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
__composer_blueprints() {
|
2018-10-08 16:23:47 +00:00
|
|
|
__composer_socket_ok && composer-cli blueprints list
|
2018-07-31 13:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__composer_sources() {
|
2018-10-08 16:23:47 +00:00
|
|
|
__composer_socket_ok && composer-cli sources list
|
2018-07-31 13:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__composer_compose_types() {
|
2018-10-08 16:23:47 +00:00
|
|
|
__composer_socket_ok && composer-cli compose types
|
2018-07-31 13:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__composer_composes() {
|
2018-10-08 16:23:47 +00:00
|
|
|
__composer_socket_ok && composer-cli compose list $@ | while read id rest; do echo $id; done
|
2018-07-31 13:39:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 00:03:35 +00:00
|
|
|
__composer_provider_list() {
|
|
|
|
__composer_socket_ok && composer-cli providers list
|
|
|
|
}
|
|
|
|
|
|
|
|
__composer_profile_list() {
|
|
|
|
__composer_socket_ok && composer-cli providers list $1
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:39:38 +00:00
|
|
|
__word_in_list() {
|
|
|
|
local w word=$1; shift
|
|
|
|
for w in "$@"; do
|
|
|
|
[ "$w" == "$word" ] && return 0
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2018-10-08 16:23:47 +00:00
|
|
|
_composer_cli() {
|
2018-07-31 13:39:38 +00:00
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
local w="" wi=0 cmd="__NONE__" subcmd="__NONE__" cmd_cword=0
|
|
|
|
|
|
|
|
# find the command and its subcommand
|
|
|
|
for (( wi=0; wi < ${#COMP_WORDS[*]}; wi++ )); do
|
|
|
|
if __word_in_list "${COMP_WORDS[wi]}" "${!__composer_cli_cmds[@]}"; then
|
|
|
|
cmd="${COMP_WORDS[wi]}"
|
|
|
|
subcmd="${COMP_WORDS[wi+1]}"
|
|
|
|
cmd_cword=$((COMP_CWORD-wi))
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
COMPREPLY=()
|
|
|
|
|
|
|
|
if [ "$cmd_cword" -le 0 ]; then
|
|
|
|
# No command yet, complete flags or commands
|
|
|
|
case "$prev" in
|
|
|
|
-s|--socket|--log)
|
|
|
|
# If it's a flag that takes a filename, suggest filenames
|
|
|
|
compopt -o filenames
|
|
|
|
COMPREPLY=($(compgen -f -- "${cur}"))
|
|
|
|
;;
|
|
|
|
-a|--api|--test)
|
|
|
|
# If it's a flag that takes an arg we can't guess, don't suggest anything
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ "${cur:0:1}" == "-" ]; then
|
|
|
|
# Suggest flags if cur starts with '-'
|
|
|
|
COMPREPLY=($(compgen -W "${__composer_cli_flags}" -- "${cur}"))
|
|
|
|
else
|
|
|
|
# Suggest commands if there isn't one already
|
|
|
|
COMPREPLY=($(compgen -W "${!__composer_cli_cmds[*]}" -- "${cur}"))
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
elif [ $cmd_cword == 1 ]; then
|
|
|
|
# Complete the word after the command
|
|
|
|
COMPREPLY=($(compgen -W "${__composer_cli_cmds[$cmd]} help" -- "${cur}"))
|
|
|
|
elif [ $cmd_cword == 2 ]; then
|
|
|
|
# Complete word(s) after subcommand
|
|
|
|
case "$cmd:$subcmd" in
|
|
|
|
compose:list)
|
|
|
|
COMPREPLY=($(compgen -W "waiting running finish failed" -- "${cur}"))
|
|
|
|
;;
|
2019-09-24 00:03:35 +00:00
|
|
|
providers:list)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_provider_list)" -- "${cur}"))
|
|
|
|
;;
|
2018-07-31 13:39:38 +00:00
|
|
|
*:list|*:help|compose:types)
|
|
|
|
COMPREPLY=()
|
|
|
|
;;
|
|
|
|
sources:info|sources:delete)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}"))
|
|
|
|
;;
|
2019-09-24 00:03:35 +00:00
|
|
|
sources:add|sources:change|blueprints:workspace|blueprints:push|providers:push)
|
2018-07-31 13:39:38 +00:00
|
|
|
compopt -o filenames
|
|
|
|
COMPREPLY=($(compgen -f -- "${cur}"))
|
|
|
|
;;
|
|
|
|
blueprints:freeze)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_blueprints) show save" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
compose:start|blueprints:*)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_blueprints)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
compose:cancel)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_composes running waiting)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
compose:delete|compose:results|compose:metadata)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_composes finished failed)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
compose:log*)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_composes running finished failed)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
compose:image)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_composes finished)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
compose:*)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_composes)" -- "${cur}"))
|
|
|
|
;;
|
2019-09-24 00:03:35 +00:00
|
|
|
upload:start)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_composes)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
providers:show|providers:save|providers:delete)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_provider_list)" -- "${cur}"))
|
|
|
|
;;
|
2018-07-31 13:39:38 +00:00
|
|
|
esac
|
|
|
|
else
|
|
|
|
# Complete words past the subcommand's argument (if appropriate)
|
|
|
|
case "$cmd:$subcmd" in
|
|
|
|
compose:delete)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_composes finished failed)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
compose:start)
|
|
|
|
if [ "$cmd_cword" == 3 ]; then
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_compose_types)" -- "${cur}"))
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
# TODO: blueprints:diff and blueprints:undo want commits
|
|
|
|
blueprints:freeze|blueprints:save|blueprints:depsolve|blueprints:changes|blueprints:show)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_blueprints)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
sources:info)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}"))
|
|
|
|
;;
|
2019-09-24 00:03:35 +00:00
|
|
|
upload:start)
|
|
|
|
if [ "$cmd_cword" == 4 ]; then
|
|
|
|
# If they have types something looking like a path, use file completion
|
|
|
|
# otherwise suggest providers.
|
|
|
|
case "${cur}" in
|
|
|
|
*/*)
|
|
|
|
compopt -o filenames
|
|
|
|
COMPREPLY=($(compgen -f -- "${cur}"))
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_provider_list)" -- "${cur}"))
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
elif [ "$cmd_cword" == 5 ]; then
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_profile_list ${prev})" -- "${cur}"))
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
providers:show|providers:save|providers:delete)
|
|
|
|
if [ "$cmd_cword" == 3 ]; then
|
|
|
|
COMPREPLY=($(compgen -W "$(__composer_profile_list ${prev})" -- "${cur}"))
|
|
|
|
fi
|
|
|
|
;;
|
2018-07-31 13:39:38 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-10-08 16:23:47 +00:00
|
|
|
complete -F _composer_cli composer-cli
|