Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20.10 backport] Add completion for docker-compose plugin #3752

Merged
merged 3 commits into from Aug 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion contrib/completion/bash/docker
Expand Up @@ -5485,6 +5485,23 @@ _docker_wait() {
_docker_container_wait
}

COMPOSE_PLUGIN_PATH=$(docker info --format '{{range .ClientInfo.Plugins}}{{if eq .Name "compose"}}{{.Path}}{{end}}{{end}}')

_docker_compose() {
local completionCommand="__completeNoDesc"
local resultArray=($COMPOSE_PLUGIN_PATH $completionCommand compose)
for value in "${words[@]:2}"; do
if [ -z "$value" ]; then
resultArray+=( "''" )
else
resultArray+=( "$value" )
fi
done
local result=$(eval "${resultArray[*]}" 2> /dev/null | grep -v '^:[0-9]*$')

COMPREPLY=( $(compgen -W "${result}" -- "$current") )
}

_docker() {
local previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob
Expand Down Expand Up @@ -5554,11 +5571,17 @@ _docker() {
wait
)

local known_plugin_commands=()

if [ -f "$COMPOSE_PLUGIN_PATH" ] ; then
known_plugin_commands+=("compose")
fi

local experimental_server_commands=(
checkpoint
)

local commands=(${management_commands[*]} ${top_level_commands[*]})
local commands=(${management_commands[*]} ${top_level_commands[*]} ${known_plugin_commands[*]})
[ -z "$DOCKER_HIDE_LEGACY_COMMANDS" ] && commands+=(${legacy_commands[*]})

# These options are valid as global options for all client commands
Expand Down