completions: Introduce transports completions

Introduces bash completions for transports which commands (copy, delete,
and inspect) support.

Signed-off-by: ERAMOTO Masaya <eramoto.masaya@jp.fujitsu.com>
This commit is contained in:
ERAMOTO Masaya
2019-02-15 14:27:55 +09:00
parent 9e2720dfcc
commit 640b967463

View File

@@ -5,11 +5,12 @@
_complete_() { _complete_() {
local options_with_args=$1 local options_with_args=$1
local boolean_options="$2 -h --help" local boolean_options="$2 -h --help"
local transports=$3
local option_with_args local option_with_args
for option_with_args in $options_with_args for option_with_args in $options_with_args $transports
do do
if [ "$option_with_args" == "$prev" ] if [ "$option_with_args" == "$prev" -o "$option_with_args" == "$cur" ]
then then
return return
fi fi
@@ -19,9 +20,22 @@ _complete_() {
-*) -*)
COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
;; ;;
*)
if [ -n "$transports" ]
then
compopt -o nospace
COMPREPLY=( $( compgen -W "$transports" -- "$cur" ) )
fi
;;
esac esac
} }
_skopeo_supported_transports() {
local subcommand=$1
${PROG} $subcommand --help | grep "Supported transports" -A 1 | tail -n 1 | sed -e 's/,/:/g' -e 's/$/:/'
}
_skopeo_copy() { _skopeo_copy() {
local options_with_args=" local options_with_args="
--authfile --authfile
@@ -43,7 +57,11 @@ _skopeo_copy() {
--remove-signatures --remove-signatures
" "
_complete_ "$options_with_args" "$boolean_options" local transports="
$(_skopeo_supported_transports $(echo $FUNCNAME | sed 's/_skopeo_//'))
"
_complete_ "$options_with_args" "$boolean_options" "$transports"
} }
_skopeo_inspect() { _skopeo_inspect() {
@@ -56,7 +74,12 @@ _skopeo_inspect() {
--raw --raw
--tls-verify --tls-verify
" "
_complete_ "$options_with_args" "$boolean_options"
local transports="
$(_skopeo_supported_transports $(echo $FUNCNAME | sed 's/_skopeo_//'))
"
_complete_ "$options_with_args" "$boolean_options" "$transports"
} }
_skopeo_standalone_sign() { _skopeo_standalone_sign() {
@@ -93,7 +116,12 @@ _skopeo_delete() {
local boolean_options=" local boolean_options="
--tls-verify --tls-verify
" "
_complete_ "$options_with_args" "$boolean_options"
local transports="
$(_skopeo_supported_transports $(echo $FUNCNAME | sed 's/_skopeo_//'))
"
_complete_ "$options_with_args" "$boolean_options" "$transports"
} }
_skopeo_layers() { _skopeo_layers() {