Signed-off-by: Harald Albers <github@albersweb.de>
| ... | ... |
@@ -328,20 +328,40 @@ __docker_complete_runtimes() {
|
| 328 | 328 |
COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") ) |
| 329 | 329 |
} |
| 330 | 330 |
|
| 331 |
-# __docker_secrets returns a list of all secrets. |
|
| 332 |
-# By default, only names of secrets are returned. |
|
| 333 |
-# Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs of secrets. |
|
| 331 |
+# __docker_secrets returns a list of secrets. Additional options to |
|
| 332 |
+# `docker secret ls` may be specified in order to filter the list, e.g. |
|
| 333 |
+# `__docker_secrets --filter label=stage=production` |
|
| 334 |
+# By default, only names are returned. |
|
| 335 |
+# Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs. |
|
| 336 |
+# An optional first option `--id|--name` may be used to limit the |
|
| 337 |
+# output to the IDs or names of matching items. This setting takes |
|
| 338 |
+# precedence over the environment setting. |
|
| 334 | 339 |
__docker_secrets() {
|
| 335 |
- local fields='$2' # default: name only |
|
| 336 |
- [ "${DOCKER_COMPLETION_SHOW_SECRET_IDS}" = yes ] && fields='$1,$2' # ID and name
|
|
| 340 |
+ local format |
|
| 341 |
+ if [ "$1" = "--id" ] ; then |
|
| 342 |
+ format='{{.ID}}'
|
|
| 343 |
+ shift |
|
| 344 |
+ elif [ "$1" = "--name" ] ; then |
|
| 345 |
+ format='{{.Name}}'
|
|
| 346 |
+ shift |
|
| 347 |
+ elif [ "$DOCKER_COMPLETION_SHOW_SECRET_IDS" = yes ] ; then |
|
| 348 |
+ format='{{.ID}} {{.Name}}'
|
|
| 349 |
+ else |
|
| 350 |
+ format='{{.Name}}'
|
|
| 351 |
+ fi |
|
| 337 | 352 |
|
| 338 |
- __docker_q secret ls | awk "NR>1 {print $fields}"
|
|
| 353 |
+ __docker_q secret ls --format "$format" "$@" |
|
| 339 | 354 |
} |
| 340 | 355 |
|
| 341 | 356 |
# __docker_complete_secrets applies completion of secrets based on the current value |
| 342 |
-# of `$cur`. |
|
| 357 |
+# of `$cur` or the value of the optional first option `--cur`, if given. |
|
| 343 | 358 |
__docker_complete_secrets() {
|
| 344 |
- COMPREPLY=( $(compgen -W "$(__docker_secrets)" -- "$cur") ) |
|
| 359 |
+ local current="$cur" |
|
| 360 |
+ if [ "$1" = "--cur" ] ; then |
|
| 361 |
+ current="$2" |
|
| 362 |
+ shift 2 |
|
| 363 |
+ fi |
|
| 364 |
+ COMPREPLY=( $(compgen -W "$(__docker_secrets "$@")" -- "$current") ) |
|
| 345 | 365 |
} |
| 346 | 366 |
|
| 347 | 367 |
# __docker_stacks returns a list of all stacks. |
| ... | ... |
@@ -3854,7 +3874,24 @@ _docker_secret_list() {
|
| 3854 | 3854 |
} |
| 3855 | 3855 |
|
| 3856 | 3856 |
_docker_secret_ls() {
|
| 3857 |
+ local key=$(__docker_map_key_of_current_option '--filter|-f') |
|
| 3858 |
+ case "$key" in |
|
| 3859 |
+ id) |
|
| 3860 |
+ __docker_complete_secrets --cur "${cur##*=}" --id
|
|
| 3861 |
+ return |
|
| 3862 |
+ ;; |
|
| 3863 |
+ name) |
|
| 3864 |
+ __docker_complete_secrets --cur "${cur##*=}" --name
|
|
| 3865 |
+ return |
|
| 3866 |
+ ;; |
|
| 3867 |
+ esac |
|
| 3868 |
+ |
|
| 3857 | 3869 |
case "$prev" in |
| 3870 |
+ --filter|-f) |
|
| 3871 |
+ COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) ) |
|
| 3872 |
+ __docker_nospace |
|
| 3873 |
+ return |
|
| 3874 |
+ ;; |
|
| 3858 | 3875 |
--format) |
| 3859 | 3876 |
return |
| 3860 | 3877 |
;; |
| ... | ... |
@@ -3862,7 +3899,7 @@ _docker_secret_ls() {
|
| 3862 | 3862 |
|
| 3863 | 3863 |
case "$cur" in |
| 3864 | 3864 |
-*) |
| 3865 |
- COMPREPLY=( $( compgen -W "--format --help --quiet -q" -- "$cur" ) ) |
|
| 3865 |
+ COMPREPLY=( $( compgen -W "--format --filter -f --help --quiet -q" -- "$cur" ) ) |
|
| 3866 | 3866 |
;; |
| 3867 | 3867 |
esac |
| 3868 | 3868 |
} |