Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 584423d

Browse files
authored
Merge pull request #2176 from thaJeztah/19.03_backport_completion
[19.03 backport] completion script updates and fixes Upstream-commit: 5cef8fc8e5067f88e2563446506ca0cf794dab0a Component: cli
2 parents 8a39b06 + bc78bc0 commit 584423d

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

components/cli/contrib/completion/bash/docker

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,17 +550,18 @@ __docker_complete_nodes() {
550550
# output to the IDs or names of matching items. This setting takes
551551
# precedence over the environment setting.
552552
__docker_services() {
553-
local fields='$2' # default: service name only
554-
[ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name
553+
local format='{{.Name}}' # default: service name only
554+
[ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && format='{{.ID}} {{.Name}}' # ID & name
555555

556556
if [ "$1" = "--id" ] ; then
557-
fields='$1' # IDs only
557+
format='{{.ID}}' # IDs only
558558
shift
559559
elif [ "$1" = "--name" ] ; then
560-
fields='$2' # names only
560+
format='{{.Name}}' # names only
561561
shift
562562
fi
563-
__docker_q service ls "$@" | awk "NR>1 {print $fields}"
563+
564+
__docker_q service ls --quiet --format "$format" "$@"
564565
}
565566

566567
# __docker_complete_services applies completion of services based on the current
@@ -572,7 +573,7 @@ __docker_complete_services() {
572573
current="$2"
573574
shift 2
574575
fi
575-
COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") )
576+
COMPREPLY=( $(__docker_services "$@" --filter "name=$current") )
576577
}
577578

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

12051206
_docker_builder() {
12061207
local subcommands="
1208+
build
12071209
prune
12081210
"
12091211
__docker_subcommands "$subcommands" && return
@@ -1218,6 +1220,10 @@ _docker_builder() {
12181220
esac
12191221
}
12201222

1223+
_docker_builder_build() {
1224+
_docker_image_build
1225+
}
1226+
12211227
_docker_builder_prune() {
12221228
case "$prev" in
12231229
--filter)

components/cli/contrib/completion/fish/docker.fish

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
function __fish_docker_no_subcommand --description 'Test if docker has yet to be given the subcommand'
1818
for i in (commandline -opc)
19-
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
19+
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
2020
return 1
2121
end
2222
end
@@ -34,6 +34,11 @@ function __fish_print_docker_containers --description 'Print a list of docker co
3434
end
3535
end
3636

37+
function __fish_print_docker_networks --description 'Print a list of docker networks'
38+
docker network ls --format "{{.ID}}\n{{.Name}}" | tr ',' '\n'
39+
end
40+
41+
3742
function __fish_docker_no_subcommand_trust --description 'Test if docker has yet to be given the trust subcommand'
3843
if __fish_seen_subcommand_from trust
3944
for i in (commandline -opc)
@@ -370,6 +375,21 @@ complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -l since -d 'Show
370375
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)'
371376
complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -a '(__fish_print_docker_containers running)' -d "Container"
372377

378+
# network
379+
complete -c docker -f -n '__fish_docker_no_subcommand' -a network -d 'Manage networks'
380+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a connect -d 'Connect a container to a network'
381+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a create -d 'Create a network'
382+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a disconnect -d 'Disconnect a container from a network'
383+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a inspect -d 'Display detailed information on one or more networks'
384+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a ls -d 'List networks'
385+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a prune -d 'Remove all unused networks'
386+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -a rm -d 'Remove one or more networks'
387+
complete -c docker -A -f -n '__fish_seen_subcommand_from network' -l help -d 'Print usage'
388+
complete -c docker -A -f -n '__fish_seen_subcommand_from network rm' -a '(__fish_print_docker_networks)' -d "Network"
389+
complete -c docker -A -f -n '__fish_seen_subcommand_from network connect' -a '(__fish_print_docker_networks)' -d "Network"
390+
complete -c docker -A -f -n '__fish_seen_subcommand_from network disconnect' -a '(__fish_print_docker_networks)' -d "Network"
391+
complete -c docker -A -f -n '__fish_seen_subcommand_from network inspect' -a '(__fish_print_docker_networks)' -d "Network"
392+
373393
# port
374394
complete -c docker -f -n '__fish_docker_no_subcommand' -a port -d 'Lookup the public-facing port that is NAT-ed to PRIVATE_PORT'
375395
complete -c docker -A -f -n '__fish_seen_subcommand_from port' -l help -d 'Print usage'

0 commit comments

Comments
 (0)