Merge pull request #1071 from edubxb/docker-compose-completion
Update docker-compose completion to the latest onepull/1075/head
commit
825ada636c
|
|
@ -1,4 +1,4 @@
|
||||||
#!bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# bash completion for docker-compose
|
# bash completion for docker-compose
|
||||||
#
|
#
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
__docker_compose_q() {
|
__docker_compose_q() {
|
||||||
docker-compose 2>/dev/null $daemon_options "$@"
|
docker-compose 2>/dev/null "${top_level_options[@]}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Transforms a multiline list of strings into a single line string
|
# Transforms a multiline list of strings into a single line string
|
||||||
|
|
@ -36,6 +36,18 @@ __docker_compose_to_extglob() {
|
||||||
echo "@($extglob)"
|
echo "@($extglob)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Determines whether the option passed as the first argument exist on
|
||||||
|
# the commandline. The option may be a pattern, e.g. `--force|-f`.
|
||||||
|
__docker_compose_has_option() {
|
||||||
|
local pattern="$1"
|
||||||
|
for (( i=2; i < $cword; ++i)); do
|
||||||
|
if [[ ${words[$i]} =~ ^($pattern)$ ]] ; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# suppress trailing whitespace
|
# suppress trailing whitespace
|
||||||
__docker_compose_nospace() {
|
__docker_compose_nospace() {
|
||||||
# compopt is not available in ancient bash versions
|
# compopt is not available in ancient bash versions
|
||||||
|
|
@ -98,9 +110,17 @@ __docker_compose_services_stopped() {
|
||||||
|
|
||||||
|
|
||||||
_docker_compose_build() {
|
_docker_compose_build() {
|
||||||
|
case "$prev" in
|
||||||
|
--build-arg)
|
||||||
|
COMPREPLY=( $( compgen -e -- "$cur" ) )
|
||||||
|
__docker_compose_nospace
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "--force-rm --help --no-cache --pull" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--build-arg --force-rm --help --no-cache --pull" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_compose_services_from_build
|
__docker_compose_services_from_build
|
||||||
|
|
@ -117,19 +137,19 @@ _docker_compose_bundle() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
COMPREPLY=( $( compgen -W "--fetch-digests --help --output -o" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--push-images --help --output -o" -- "$cur" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_docker_compose_config() {
|
_docker_compose_config() {
|
||||||
COMPREPLY=( $( compgen -W "--help --quiet -q --services" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--help --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_docker_compose_create() {
|
_docker_compose_create() {
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "--force-recreate --help --no-build --no-recreate" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--build --force-recreate --help --no-build --no-recreate" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_compose_services_all
|
__docker_compose_services_all
|
||||||
|
|
@ -148,14 +168,18 @@ _docker_compose_docker_compose() {
|
||||||
_filedir "y?(a)ml"
|
_filedir "y?(a)ml"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
$(__docker_compose_to_extglob "$daemon_options_with_args") )
|
--project-directory)
|
||||||
|
_filedir -d
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
$(__docker_compose_to_extglob "$top_level_options_with_args") )
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "$daemon_boolean_options $daemon_options_with_args --help -h --verbose --version -v" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "$top_level_boolean_options $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
|
||||||
|
|
@ -200,14 +224,14 @@ _docker_compose_events() {
|
||||||
|
|
||||||
_docker_compose_exec() {
|
_docker_compose_exec() {
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
--index|--user)
|
--index|--user|-u)
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "-d --help --index --privileged -T --user" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "-d --help --index --privileged -T --user -u" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_compose_services_running
|
__docker_compose_services_running
|
||||||
|
|
@ -220,6 +244,16 @@ _docker_compose_help() {
|
||||||
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_docker_compose_images() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help -q" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
__docker_compose_services_all
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
_docker_compose_kill() {
|
_docker_compose_kill() {
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
|
|
@ -307,7 +341,7 @@ _docker_compose_ps() {
|
||||||
_docker_compose_pull() {
|
_docker_compose_pull() {
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "--help --ignore-pull-failures" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--help --ignore-pull-failures --parallel --quiet" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_compose_services_from_image
|
__docker_compose_services_from_image
|
||||||
|
|
@ -349,10 +383,14 @@ _docker_compose_restart() {
|
||||||
_docker_compose_rm() {
|
_docker_compose_rm() {
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "--force -f --help -v" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--force -f --help --stop -s -v" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
if __docker_compose_has_option "--stop|-s" ; then
|
||||||
|
__docker_compose_services_all
|
||||||
|
else
|
||||||
__docker_compose_services_stopped
|
__docker_compose_services_stopped
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
@ -365,14 +403,14 @@ _docker_compose_run() {
|
||||||
__docker_compose_nospace
|
__docker_compose_nospace
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--entrypoint|--name|--user|-u|--workdir|-w)
|
--entrypoint|--name|--user|-u|--volume|-v|--workdir|-w)
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "-d --entrypoint -e --help --name --no-deps --publish -p --rm --service-ports -T --user -u --workdir -w" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "-d --entrypoint -e --help --name --no-deps --publish -p --rm --service-ports -T --user -u --volume -v --workdir -w" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_compose_services_all
|
__docker_compose_services_all
|
||||||
|
|
@ -434,6 +472,18 @@ _docker_compose_stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_docker_compose_top() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
__docker_compose_services_running
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_docker_compose_unpause() {
|
_docker_compose_unpause() {
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
|
|
@ -448,6 +498,19 @@ _docker_compose_unpause() {
|
||||||
|
|
||||||
_docker_compose_up() {
|
_docker_compose_up() {
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
|
=)
|
||||||
|
COMPREPLY=("$cur")
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
--exit-code-from)
|
||||||
|
__docker_compose_services_all
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
--scale)
|
||||||
|
COMPREPLY=( $(compgen -S "=" -W "$(___docker_compose_all_services_in_compose_file)" -- "$cur") )
|
||||||
|
__docker_compose_nospace
|
||||||
|
return
|
||||||
|
;;
|
||||||
--timeout|-t)
|
--timeout|-t)
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
|
@ -455,7 +518,7 @@ _docker_compose_up() {
|
||||||
|
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "--abort-on-container-exit --build -d --force-recreate --help --no-build --no-color --no-deps --no-recreate --timeout -t --remove-orphans" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--abort-on-container-exit --build -d --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --remove-orphans --scale --timeout -t" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_compose_services_all
|
__docker_compose_services_all
|
||||||
|
|
@ -486,6 +549,7 @@ _docker_compose() {
|
||||||
events
|
events
|
||||||
exec
|
exec
|
||||||
help
|
help
|
||||||
|
images
|
||||||
kill
|
kill
|
||||||
logs
|
logs
|
||||||
pause
|
pause
|
||||||
|
|
@ -499,21 +563,25 @@ _docker_compose() {
|
||||||
scale
|
scale
|
||||||
start
|
start
|
||||||
stop
|
stop
|
||||||
|
top
|
||||||
unpause
|
unpause
|
||||||
up
|
up
|
||||||
version
|
version
|
||||||
)
|
)
|
||||||
|
|
||||||
# options for the docker daemon that have to be passed to secondary calls to
|
# Options for the docker daemon that have to be passed to secondary calls to
|
||||||
# docker-compose executed by this script
|
# docker-compose executed by this script.
|
||||||
local daemon_boolean_options="
|
# Other global otions that are not relevant for secondary calls are defined in
|
||||||
|
# `_docker_compose_docker_compose`.
|
||||||
|
local top_level_boolean_options="
|
||||||
--skip-hostname-check
|
--skip-hostname-check
|
||||||
--tls
|
--tls
|
||||||
--tlsverify
|
--tlsverify
|
||||||
"
|
"
|
||||||
local daemon_options_with_args="
|
local top_level_options_with_args="
|
||||||
--file -f
|
--file -f
|
||||||
--host -H
|
--host -H
|
||||||
|
--project-directory
|
||||||
--project-name -p
|
--project-name -p
|
||||||
--tlscacert
|
--tlscacert
|
||||||
--tlscert
|
--tlscert
|
||||||
|
|
@ -527,19 +595,19 @@ _docker_compose() {
|
||||||
# search subcommand and invoke its handler.
|
# search subcommand and invoke its handler.
|
||||||
# special treatment of some top-level options
|
# special treatment of some top-level options
|
||||||
local command='docker_compose'
|
local command='docker_compose'
|
||||||
local daemon_options=()
|
local top_level_options=()
|
||||||
local counter=1
|
local counter=1
|
||||||
|
|
||||||
while [ $counter -lt $cword ]; do
|
while [ $counter -lt $cword ]; do
|
||||||
case "${words[$counter]}" in
|
case "${words[$counter]}" in
|
||||||
$(__docker_compose_to_extglob "$daemon_boolean_options") )
|
$(__docker_compose_to_extglob "$top_level_boolean_options") )
|
||||||
local opt=${words[counter]}
|
local opt=${words[counter]}
|
||||||
daemon_options+=($opt)
|
top_level_options+=($opt)
|
||||||
;;
|
;;
|
||||||
$(__docker_compose_to_extglob "$daemon_options_with_args") )
|
$(__docker_compose_to_extglob "$top_level_options_with_args") )
|
||||||
local opt=${words[counter]}
|
local opt=${words[counter]}
|
||||||
local arg=${words[++counter]}
|
local arg=${words[++counter]}
|
||||||
daemon_options+=($opt $arg)
|
top_level_options+=($opt $arg)
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
;;
|
;;
|
||||||
|
|
@ -558,4 +626,4 @@ _docker_compose() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _docker_compose docker-compose
|
complete -F _docker_compose docker-compose docker-compose.exe
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue