mirror of https://github.com/docker/compose.git
prepare bash completion for new TLS options
Up to now there were two special top-level options that required special treatment: --project-name and --file (and their short forms). For 1.7.0, several TLS related options were added that have to be passed to secondary docker-compose invocations as well. This commit introduces a scalable treatment of those options. Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
parent
2a09fb02db
commit
9094c4d97d
|
@ -18,11 +18,22 @@
|
|||
|
||||
|
||||
__docker_compose_q() {
|
||||
local file_args
|
||||
if [ ${#compose_files[@]} -ne 0 ] ; then
|
||||
file_args="${compose_files[@]/#/-f }"
|
||||
fi
|
||||
docker-compose 2>/dev/null $file_args ${compose_project:+-p $compose_project} "$@"
|
||||
docker-compose 2>/dev/null $daemon_options "$@"
|
||||
}
|
||||
|
||||
# Transforms a multiline list of strings into a single line string
|
||||
# with the words separated by "|".
|
||||
__docker_compose_to_alternatives() {
|
||||
local parts=( $1 )
|
||||
local IFS='|'
|
||||
echo "${parts[*]}"
|
||||
}
|
||||
|
||||
# Transforms a multiline list of options into an extglob pattern
|
||||
# suitable for use in case statements.
|
||||
__docker_compose_to_extglob() {
|
||||
local extglob=$( __docker_compose_to_alternatives "$1" )
|
||||
echo "@($extglob)"
|
||||
}
|
||||
|
||||
# suppress trailing whitespace
|
||||
|
@ -31,20 +42,6 @@ __docker_compose_nospace() {
|
|||
type compopt &>/dev/null && compopt -o nospace
|
||||
}
|
||||
|
||||
# For compatibility reasons, Compose and therefore its completion supports several
|
||||
# stack compositon files as listed here, in descending priority.
|
||||
# Support for these filenames might be dropped in some future version.
|
||||
__docker_compose_compose_file() {
|
||||
local file
|
||||
for file in docker-compose.y{,a}ml ; do
|
||||
[ -e $file ] && {
|
||||
echo $file
|
||||
return
|
||||
}
|
||||
done
|
||||
echo docker-compose.yml
|
||||
}
|
||||
|
||||
# Extracts all service names from the compose file.
|
||||
___docker_compose_all_services_in_compose_file() {
|
||||
__docker_compose_q config --services
|
||||
|
@ -142,7 +139,7 @@ _docker_compose_docker_compose() {
|
|||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--file -f --help -h --project-name -p --verbose --version -v" -- "$cur" ) )
|
||||
COMPREPLY=( $( compgen -W "$daemon_options_with_args --help -h --verbose --version -v" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
|
||||
|
@ -452,6 +449,13 @@ _docker_compose() {
|
|||
version
|
||||
)
|
||||
|
||||
# options for the docker daemon that have to be passed to secondary calls to
|
||||
# docker-compose executed by this script
|
||||
local daemon_options_with_args="
|
||||
--file -f
|
||||
--project-name -p
|
||||
"
|
||||
|
||||
COMPREPLY=()
|
||||
local cur prev words cword
|
||||
_get_comp_words_by_ref -n : cur prev words cword
|
||||
|
@ -459,17 +463,15 @@ _docker_compose() {
|
|||
# search subcommand and invoke its handler.
|
||||
# special treatment of some top-level options
|
||||
local command='docker_compose'
|
||||
local daemon_options=()
|
||||
local counter=1
|
||||
local compose_files=() compose_project
|
||||
|
||||
while [ $counter -lt $cword ]; do
|
||||
case "${words[$counter]}" in
|
||||
--file|-f)
|
||||
(( counter++ ))
|
||||
compose_files+=(${words[$counter]})
|
||||
;;
|
||||
--project-name|-p)
|
||||
(( counter++ ))
|
||||
compose_project="${words[$counter]}"
|
||||
$(__docker_compose_to_extglob "$daemon_options_with_args") )
|
||||
local opt=${words[counter]}
|
||||
local arg=${words[++counter]}
|
||||
daemon_options+=($opt $arg)
|
||||
;;
|
||||
-*)
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue