Skip to content

Commit

Permalink
Merge pull request #2176 from thaJeztah/19.03_backport_completion
Browse files Browse the repository at this point in the history
[19.03 backport] completion script updates and fixes
  • Loading branch information
andrewhsu authored Oct 29, 2019
2 parents 8a9e86c + 57332bc commit 5cef8fc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
18 changes: 12 additions & 6 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,18 @@ __docker_complete_nodes() {
# output to the IDs or names of matching items. This setting takes
# precedence over the environment setting.
__docker_services() {
local fields='$2' # default: service name only
[ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name
local format='{{.Name}}' # default: service name only
[ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && format='{{.ID}} {{.Name}}' # ID & name

if [ "$1" = "--id" ] ; then
fields='$1' # IDs only
format='{{.ID}}' # IDs only
shift
elif [ "$1" = "--name" ] ; then
fields='$2' # names only
format='{{.Name}}' # names only
shift
fi
__docker_q service ls "$@" | awk "NR>1 {print $fields}"

__docker_q service ls --quiet --format "$format" "$@"
}

# __docker_complete_services applies completion of services based on the current
Expand All @@ -572,7 +573,7 @@ __docker_complete_services() {
current="$2"
shift 2
fi
COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") )
COMPREPLY=( $(__docker_services "$@" --filter "name=$current") )
}

# __docker_tasks returns a list of all task IDs.
Expand Down Expand Up @@ -1204,6 +1205,7 @@ _docker_build() {

_docker_builder() {
local subcommands="
build
prune
"
__docker_subcommands "$subcommands" && return
Expand All @@ -1218,6 +1220,10 @@ _docker_builder() {
esac
}

_docker_builder_build() {
_docker_image_build
}

_docker_builder_prune() {
case "$prev" in
--filter)
Expand Down
22 changes: 21 additions & 1 deletion contrib/completion/fish/docker.fish
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

function __fish_docker_no_subcommand --description 'Test if docker has yet to be given the subcommand'
for i in (commandline -opc)
if contains -- $i attach build commit cp create diff events exec export history images import info inspect kill load login logout logs pause port ps pull push rename restart rm rmi run save search start stop tag top trust unpause version wait stats
if contains -- $i attach build commit cp create diff events exec export history images import info inspect kill load login logout logs network pause port ps pull push rename restart rm rmi run save search start stop tag top trust unpause version wait stats
return 1
end
end
Expand All @@ -34,6 +34,11 @@ function __fish_print_docker_containers --description 'Print a list of docker co
end
end

function __fish_print_docker_networks --description 'Print a list of docker networks'
docker network ls --format "{{.ID}}\n{{.Name}}" | tr ',' '\n'
end


function __fish_docker_no_subcommand_trust --description 'Test if docker has yet to be given the trust subcommand'
if __fish_seen_subcommand_from trust
for i in (commandline -opc)
Expand Down Expand Up @@ -370,6 +375,21 @@ complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -l since -d 'Show
complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -l tail -d 'Output the specified number of lines at the end of logs (defaults to all logs)'
complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -a '(__fish_print_docker_containers running)' -d "Container"

# network
complete -c docker -f -n '__fish_docker_no_subcommand' -a network -d 'Manage networks'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a connect -d 'Connect a container to a network'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a create -d 'Create a network'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a disconnect -d 'Disconnect a container from a network'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a inspect -d 'Display detailed information on one or more networks'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a ls -d 'List networks'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a prune -d 'Remove all unused networks'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a rm -d 'Remove one or more networks'
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -l help -d 'Print usage'
complete -c docker -A -f -n '__fish_seen_subcommand_from network rm' -a '(__fish_print_docker_networks)' -d "Network"
complete -c docker -A -f -n '__fish_seen_subcommand_from network connect' -a '(__fish_print_docker_networks)' -d "Network"
complete -c docker -A -f -n '__fish_seen_subcommand_from network disconnect' -a '(__fish_print_docker_networks)' -d "Network"
complete -c docker -A -f -n '__fish_seen_subcommand_from network inspect' -a '(__fish_print_docker_networks)' -d "Network"

# port
complete -c docker -f -n '__fish_docker_no_subcommand' -a port -d 'Lookup the public-facing port that is NAT-ed to PRIVATE_PORT'
complete -c docker -A -f -n '__fish_seen_subcommand_from port' -l help -d 'Print usage'
Expand Down

0 comments on commit 5cef8fc

Please sign in to comment.