bash completion for `docker volume`

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2015-09-07 13:18:29 -07:00
parent 13d1f0c1a1
commit 57ab4a1a6c
1 changed files with 98 additions and 0 deletions

View File

@ -138,6 +138,10 @@ __docker_containers_and_images() {
COMPREPLY+=( "${containers[@]}" )
}
__docker_volumes() {
COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") )
}
# Finds the position of the first word that is neither option nor an option's argument.
# If there are options that require arguments, you should pass a glob describing those
# options, e.g. "--option1|-o|--option2"
@ -1441,6 +1445,99 @@ _docker_version() {
esac
}
_docker_volume_create() {
case "$prev" in
--driver|-d)
COMPREPLY=( $( compgen -W "local" -- "$cur" ) )
return
;;
--name|--opt|-o)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--driver -d --help --name --opt -o" -- "$cur" ) )
;;
esac
}
_docker_volume_inspect() {
case "$prev" in
--format|-f)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
;;
*)
__docker_volumes
;;
esac
}
_docker_volume_ls() {
case "$prev" in
--filter|-f)
COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) )
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
;;
esac
}
_docker_volume_rm() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_volumes
;;
esac
}
_docker_volume() {
local subcommands=(
create
inspect
ls
rm
)
local counter=$(($command_pos + 1))
while [ $counter -lt $cword ]; do
case "${words[$counter]}" in
$(__docker_to_extglob "${subcommands[*]}") )
local subcommand=${words[$counter]}
local completions_func=_docker_volume_$subcommand
declare -F $completions_func >/dev/null && $completions_func
return
;;
esac
(( counter++ ))
done
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W "${subcommands[*]}" -- "$cur" ) )
;;
esac
}
_docker_wait() {
case "$cur" in
-*)
@ -1496,6 +1593,7 @@ _docker() {
top
unpause
version
volume
wait
)