mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add bash completion for plugin API
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit ecb707cb0f
)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
fcc38c048c
commit
46b8a5fb57
1 changed files with 192 additions and 12 deletions
|
@ -237,11 +237,13 @@ __docker_complete_volumes() {
|
||||||
COMPREPLY=( $(compgen -W "$(__docker_volumes "$@")" -- "$current") )
|
COMPREPLY=( $(compgen -W "$(__docker_volumes "$@")" -- "$current") )
|
||||||
}
|
}
|
||||||
|
|
||||||
# __docker_plugins returns a list of all plugins of a given type.
|
# __docker_plugins_bundled returns a list of all plugins of a given type.
|
||||||
# The type has to be specified with the mandatory option `--type`.
|
# The type has to be specified with the mandatory option `--type`.
|
||||||
# Valid types are: Network, Volume, Authorization.
|
# Valid types are: Network, Volume, Authorization.
|
||||||
# Completions may be added or removed with `--add` and `--remove`
|
# Completions may be added or removed with `--add` and `--remove`
|
||||||
__docker_plugins() {
|
# This function only deals with plugins that come bundled with Docker.
|
||||||
|
# For plugins managed by `docker plugin`, see `__docker_plugins_installed`.
|
||||||
|
__docker_plugins_bundled() {
|
||||||
local type add=() remove=()
|
local type add=() remove=()
|
||||||
while true ; do
|
while true ; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -270,16 +272,39 @@ __docker_plugins() {
|
||||||
echo "${plugins[@]} ${add[@]}"
|
echo "${plugins[@]} ${add[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# __docker_complete_plugins applies completion of plugins based on the current
|
# __docker_complete_plugins_bundled applies completion of plugins based on the current
|
||||||
# value of `$cur` or the value of the optional first option `--cur`, if given.
|
# value of `$cur` or the value of the optional first option `--cur`, if given.
|
||||||
# The plugin type has to be specified with the next option `--type`.
|
# The plugin type has to be specified with the next option `--type`.
|
||||||
__docker_complete_plugins() {
|
# This function only deals with plugins that come bundled with Docker.
|
||||||
|
# For completion of plugins managed by `docker plugin`, see
|
||||||
|
# `__docker_complete_plugins_installed`.
|
||||||
|
__docker_complete_plugins_bundled() {
|
||||||
local current="$cur"
|
local current="$cur"
|
||||||
if [ "$1" = "--cur" ] ; then
|
if [ "$1" = "--cur" ] ; then
|
||||||
current="$2"
|
current="$2"
|
||||||
shift 2
|
shift 2
|
||||||
fi
|
fi
|
||||||
COMPREPLY=( $(compgen -W "$(__docker_plugins "$@")" -- "$current") )
|
COMPREPLY=( $(compgen -W "$(__docker_plugins_bundled "$@")" -- "$current") )
|
||||||
|
}
|
||||||
|
|
||||||
|
# __docker_plugins_installed returns a list of all plugins that were installed with
|
||||||
|
# the Docker plugin API.
|
||||||
|
# For built-in pugins, see `__docker_plugins_bundled`.
|
||||||
|
__docker_plugins_installed() {
|
||||||
|
__docker_q plugin ls | awk 'NR>1 {print $1}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# __docker_complete_plugins_installed applies completion of plugins that were installed
|
||||||
|
# with the Docker plugin API, based on the current value of `$cur` or the value of
|
||||||
|
# the optional first option `--cur`, if given.
|
||||||
|
# For completion of built-in pugins, see `__docker_complete_plugins_bundled`.
|
||||||
|
__docker_complete_plugins_installed() {
|
||||||
|
local current="$cur"
|
||||||
|
if [ "$1" = "--cur" ] ; then
|
||||||
|
current="$2"
|
||||||
|
shift 2
|
||||||
|
fi
|
||||||
|
COMPREPLY=( $(compgen -W "$(__docker_plugins_installed "$@")" -- "$current") )
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_runtimes() {
|
__docker_runtimes() {
|
||||||
|
@ -1439,7 +1464,7 @@ _docker_container_run() {
|
||||||
__docker_complete_containers_all --cur "${cur#*:}"
|
__docker_complete_containers_all --cur "${cur#*:}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") )
|
COMPREPLY=( $( compgen -W "$(__docker_plugins_bundled --type Network) $(__docker_networks) container:" -- "$cur") )
|
||||||
if [ "${COMPREPLY[*]}" = "container:" ] ; then
|
if [ "${COMPREPLY[*]}" = "container:" ] ; then
|
||||||
__docker_nospace
|
__docker_nospace
|
||||||
fi
|
fi
|
||||||
|
@ -1486,7 +1511,7 @@ _docker_container_run() {
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--volume-driver)
|
--volume-driver)
|
||||||
__docker_complete_plugins --type Volume
|
__docker_complete_plugins_bundled --type Volume
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--volumes-from)
|
--volumes-from)
|
||||||
|
@ -1742,7 +1767,7 @@ _docker_daemon() {
|
||||||
|
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
--authorization-plugin)
|
--authorization-plugin)
|
||||||
__docker_complete_plugins --type Authorization
|
__docker_complete_plugins_bundled --type Authorization
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--cluster-store)
|
--cluster-store)
|
||||||
|
@ -2348,7 +2373,7 @@ _docker_network_create() {
|
||||||
;;
|
;;
|
||||||
--driver|-d)
|
--driver|-d)
|
||||||
# remove drivers that allow one instance only, add drivers missing in `docker info`
|
# remove drivers that allow one instance only, add drivers missing in `docker info`
|
||||||
__docker_complete_plugins --type Network --remove host --remove null --add macvlan
|
__docker_complete_plugins_bundled --type Network --remove host --remove null --add macvlan
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--label)
|
--label)
|
||||||
|
@ -2399,7 +2424,7 @@ _docker_network_ls() {
|
||||||
local key=$(__docker_map_key_of_current_option '--filter|-f')
|
local key=$(__docker_map_key_of_current_option '--filter|-f')
|
||||||
case "$key" in
|
case "$key" in
|
||||||
driver)
|
driver)
|
||||||
__docker_complete_plugins --cur "${cur##*=}" --type Network --add macvlan
|
__docker_complete_plugins_bundled --cur "${cur##*=}" --type Network --add macvlan
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
id)
|
id)
|
||||||
|
@ -3049,6 +3074,160 @@ _docker_pause() {
|
||||||
_docker_container_pause
|
_docker_container_pause
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_docker_plugin() {
|
||||||
|
local subcommands="
|
||||||
|
create
|
||||||
|
disable
|
||||||
|
enable
|
||||||
|
inspect
|
||||||
|
install
|
||||||
|
ls
|
||||||
|
push
|
||||||
|
rm
|
||||||
|
set
|
||||||
|
"
|
||||||
|
local aliases="
|
||||||
|
list
|
||||||
|
remove
|
||||||
|
"
|
||||||
|
__docker_subcommands "$subcommands $aliases" && return
|
||||||
|
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_create() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--compress --help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
local counter=$(__docker_pos_first_nonflag)
|
||||||
|
if [ $cword -eq $counter ]; then
|
||||||
|
# reponame
|
||||||
|
return
|
||||||
|
elif [ $cword -eq $((counter + 1)) ]; then
|
||||||
|
_filedir -d
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_disable() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
__docker_complete_plugins_installed
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_enable() {
|
||||||
|
case "$prev" in
|
||||||
|
--timeout)
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help --timeout" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
__docker_complete_plugins_installed
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_inspect() {
|
||||||
|
case "$prev" in
|
||||||
|
--format|f)
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
__docker_complete_plugins_installed
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_install() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--disable --grant-all-permissions--help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_list() {
|
||||||
|
_docker_plugin_ls
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_ls() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help --no-trunc" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_push() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
local counter=$(__docker_pos_first_nonflag)
|
||||||
|
if [ $cword -eq $counter ]; then
|
||||||
|
__docker_complete_plugins_installed
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_remove() {
|
||||||
|
_docker_plugin_rm
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_rm() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
__docker_complete_plugins_installed
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_docker_plugin_set() {
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
local counter=$(__docker_pos_first_nonflag)
|
||||||
|
if [ $cword -eq $counter ]; then
|
||||||
|
__docker_complete_plugins_installed
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_docker_port() {
|
_docker_port() {
|
||||||
_docker_container_port
|
_docker_container_port
|
||||||
}
|
}
|
||||||
|
@ -3300,7 +3479,7 @@ _docker_version() {
|
||||||
_docker_volume_create() {
|
_docker_volume_create() {
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
--driver|-d)
|
--driver|-d)
|
||||||
__docker_complete_plugins --type Volume
|
__docker_complete_plugins_bundled --type Volume
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--label|--opt|-o)
|
--label|--opt|-o)
|
||||||
|
@ -3340,7 +3519,7 @@ _docker_volume_ls() {
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
driver)
|
driver)
|
||||||
__docker_complete_plugins --cur "${cur##*=}" --type Volume
|
__docker_complete_plugins_bundled --cur "${cur##*=}" --type Volume
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
name)
|
name)
|
||||||
|
@ -3440,6 +3619,7 @@ _docker() {
|
||||||
network
|
network
|
||||||
node
|
node
|
||||||
pause
|
pause
|
||||||
|
plugin
|
||||||
port
|
port
|
||||||
ps
|
ps
|
||||||
pull
|
pull
|
||||||
|
|
Loading…
Add table
Reference in a new issue