mirror of https://github.com/docker/cli.git
Add zsh completion for 'docker network ls -f {id,name,type}'
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
This commit is contained in:
parent
64ba15e3a3
commit
586ec24a48
|
@ -311,11 +311,42 @@ __docker_complete_ps_filters() {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_networks() {
|
__docker_network_complete_ls_filters() {
|
||||||
[[ $PREFIX = -* ]] && return 1
|
[[ $PREFIX = -* ]] && return 1
|
||||||
integer ret=1
|
integer ret=1
|
||||||
|
|
||||||
|
if compset -P '*='; then
|
||||||
|
case "${${words[-1]%=*}#*=}" in
|
||||||
|
(id)
|
||||||
|
__docker_networks_ids && ret=0
|
||||||
|
;;
|
||||||
|
(name)
|
||||||
|
__docker_networks_names && ret=0
|
||||||
|
;;
|
||||||
|
(type)
|
||||||
|
type_opts=('builtin' 'custom')
|
||||||
|
_describe -t type-filter-opts "Type Filter Options" type_opts && ret=0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_message 'value' && ret=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
opts=('id' 'name' 'type')
|
||||||
|
_describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
__docker_get_networks() {
|
||||||
|
[[ $PREFIX = -* ]] && return 1
|
||||||
|
integer ret=1
|
||||||
|
local line s
|
||||||
declare -a lines networks
|
declare -a lines networks
|
||||||
|
|
||||||
|
type=$1; shift
|
||||||
|
|
||||||
lines=(${(f)"$(_call_program commands docker $docker_options network ls)"})
|
lines=(${(f)"$(_call_program commands docker $docker_options network ls)"})
|
||||||
|
|
||||||
# Parse header line to find columns
|
# Parse header line to find columns
|
||||||
|
@ -332,24 +363,42 @@ __docker_networks() {
|
||||||
lines=(${lines[2,-1]})
|
lines=(${lines[2,-1]})
|
||||||
|
|
||||||
# Network ID
|
# Network ID
|
||||||
local line s
|
if [[ $type = (ids|all) ]]; then
|
||||||
for line in $lines; do
|
for line in $lines; do
|
||||||
s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}"
|
s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}"
|
||||||
s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
|
s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
|
||||||
networks=($networks $s)
|
networks=($networks $s)
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# Names
|
# Names
|
||||||
|
if [[ $type = (names|all) ]]; then
|
||||||
for line in $lines; do
|
for line in $lines; do
|
||||||
s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
|
s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
|
||||||
s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
|
s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
|
||||||
networks=($networks $s)
|
networks=($networks $s)
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
_describe -t networks-list "networks" networks && ret=0
|
_describe -t networks-list "networks" networks "$@" && ret=0
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__docker_networks() {
|
||||||
|
[[ $PREFIX = -* ]] && return 1
|
||||||
|
__docker_get_networks all "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
__docker_networks_ids() {
|
||||||
|
[[ $PREFIX = -* ]] && return 1
|
||||||
|
__docker_get_networks ids "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
__docker_networks_names() {
|
||||||
|
[[ $PREFIX = -* ]] && return 1
|
||||||
|
__docker_get_networks names "$@"
|
||||||
|
}
|
||||||
|
|
||||||
__docker_network_commands() {
|
__docker_network_commands() {
|
||||||
local -a _docker_network_subcommands
|
local -a _docker_network_subcommands
|
||||||
_docker_network_subcommands=(
|
_docker_network_subcommands=(
|
||||||
|
@ -423,7 +472,13 @@ __docker_network_subcommand() {
|
||||||
_arguments $(__docker_arguments) \
|
_arguments $(__docker_arguments) \
|
||||||
$opts_help \
|
$opts_help \
|
||||||
"($help)--no-trunc[Do not truncate the output]" \
|
"($help)--no-trunc[Do not truncate the output]" \
|
||||||
|
"($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
|
||||||
"($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0
|
"($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0
|
||||||
|
case $state in
|
||||||
|
(filter-options)
|
||||||
|
__docker_network_complete_ls_filters && ret=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
;;
|
;;
|
||||||
(rm)
|
(rm)
|
||||||
_arguments $(__docker_arguments) \
|
_arguments $(__docker_arguments) \
|
||||||
|
|
Loading…
Reference in New Issue