Add bash completion for `docker build --target`

`--file` and `PATH` are honored if the are specified before `--target`.
Note that according to the command's syntax, PATH should be specified
after the options.

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2017-08-02 14:15:37 +02:00
parent b0cc841631
commit 647166b3bf
1 changed files with 14 additions and 0 deletions

View File

@ -2439,6 +2439,7 @@ _docker_image_build() {
--network --network
--shm-size --shm-size
--tag -t --tag -t
--target
--ulimit --ulimit
" "
__docker_daemon_os_is windows && options_with_args+=" __docker_daemon_os_is windows && options_with_args+="
@ -2505,6 +2506,19 @@ _docker_image_build() {
__docker_complete_image_repos_and_tags __docker_complete_image_repos_and_tags
return return
;; ;;
--target)
local context_pos=$( __docker_pos_first_nonflag "$( __docker_to_alternatives "$options_with_args" )" )
local context="${words[$context_pos]}"
context="${context:-.}"
local file="$( __docker_value_of_option '--file|f' )"
local default_file="${context%/}/Dockerfile"
local dockerfile="${file:-$default_file}"
local targets="$( sed -n 's/^FROM .\+ AS \(.\+\)/\1/p' "$dockerfile" 2>/dev/null )"
COMPREPLY=( $( compgen -W "$targets" -- "$cur" ) )
return
;;
$(__docker_to_extglob "$options_with_args") ) $(__docker_to_extglob "$options_with_args") )
return return
;; ;;