bash_completion: Add support for new composer-cli commands

This commit is contained in:
Brian C. Lane 2019-09-23 17:03:35 -07:00
parent 4276a68cf3
commit 1969711d8c

View File

@ -8,6 +8,8 @@ declare -A __composer_cli_cmds=(
[modules]="list" [modules]="list"
[projects]="list info" [projects]="list info"
[sources]="list info add change delete" [sources]="list info add change delete"
[upload]="info start log cancel delete reset"
[providers]="list show push save delete"
[help]="" [help]=""
) )
@ -31,6 +33,14 @@ __composer_composes() {
__composer_socket_ok && composer-cli compose list $@ | while read id rest; do echo $id; done __composer_socket_ok && composer-cli compose list $@ | while read id rest; do echo $id; done
} }
__composer_provider_list() {
__composer_socket_ok && composer-cli providers list
}
__composer_profile_list() {
__composer_socket_ok && composer-cli providers list $1
}
__word_in_list() { __word_in_list() {
local w word=$1; shift local w word=$1; shift
for w in "$@"; do for w in "$@"; do
@ -86,13 +96,16 @@ _composer_cli() {
compose:list) compose:list)
COMPREPLY=($(compgen -W "waiting running finish failed" -- "${cur}")) COMPREPLY=($(compgen -W "waiting running finish failed" -- "${cur}"))
;; ;;
providers:list)
COMPREPLY=($(compgen -W "$(__composer_provider_list)" -- "${cur}"))
;;
*:list|*:help|compose:types) *:list|*:help|compose:types)
COMPREPLY=() COMPREPLY=()
;; ;;
sources:info|sources:delete) sources:info|sources:delete)
COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}")) COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}"))
;; ;;
sources:add|sources:change|blueprints:workspace|blueprints:push) sources:add|sources:change|blueprints:workspace|blueprints:push|providers:push)
compopt -o filenames compopt -o filenames
COMPREPLY=($(compgen -f -- "${cur}")) COMPREPLY=($(compgen -f -- "${cur}"))
;; ;;
@ -117,6 +130,12 @@ _composer_cli() {
compose:*) compose:*)
COMPREPLY=($(compgen -W "$(__composer_composes)" -- "${cur}")) COMPREPLY=($(compgen -W "$(__composer_composes)" -- "${cur}"))
;; ;;
upload:start)
COMPREPLY=($(compgen -W "$(__composer_composes)" -- "${cur}"))
;;
providers:show|providers:save|providers:delete)
COMPREPLY=($(compgen -W "$(__composer_provider_list)" -- "${cur}"))
;;
esac esac
else else
# Complete words past the subcommand's argument (if appropriate) # Complete words past the subcommand's argument (if appropriate)
@ -136,6 +155,28 @@ _composer_cli() {
sources:info) sources:info)
COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}")) COMPREPLY=($(compgen -W "$(__composer_sources)" -- "${cur}"))
;; ;;
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
;;
esac esac
fi fi
} }