From 1f5e5ff4715885b1e97f801fcf274e6868c7be59 Mon Sep 17 00:00:00 2001 From: midchildan Date: Tue, 30 Nov 2021 00:52:28 +0900 Subject: [PATCH] knife: improve completion for Chef Vault commands --- src/_knife | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/_knife b/src/_knife index 7a0c4a0..dc839ef 100644 --- a/src/_knife +++ b/src/_knife @@ -134,7 +134,7 @@ _knife() { site) compadd "$@" vendor show share search download list unshare ;; - show|delete|edit) + show|delete|edit|update) _arguments '3:Subsubcommands:($(_knife_list_remote "$words[2]"))' ;; upload|test) @@ -168,6 +168,16 @@ _knife() { node|client|role) compadd "$@" --attribute ;; + vault) + _arguments '4:Keys:($(_knife_list_remote "$words[2]" "$words[4]"))' + ;; + esac + ;; + update) + case "$words[2]" in + vault) + _arguments '4:Keys:($(_knife_list_remote "$words[2]" "$words[4]"))' + ;; esac ;; esac @@ -249,18 +259,21 @@ _knife_options3() { # get a list of objects of type x on the server _knife_list_remote() { case "$*" in - role|client|node|cookbook|"cookbook site"|"data bag"|environment|user) + role|client|node|cookbook|"cookbook site"|"data bag"|environment|user|vault) + _call_program commands knife "$@" list --format json \ + | grep \" \ + | awk '{print $1}' \ + | awk -F"," '{print $1}' \ + | awk -F"\"" '{print $2}' ;; - *) - return + "vault "*) + _call_program commands knife vault show "$2" --format json \ + | grep \" \ + | awk '{print $1}' \ + | awk -F"," '{print $1}' \ + | awk -F"\"" '{print $2}' ;; esac - - _call_program commands knife "$@" list --format json \ - | grep \" \ - | awk '{print $1}' \ - | awk -F"," '{print $1}' \ - | awk -F"\"" '{print $2}' } # The chef_x_local functions use the knife config to find the paths of relevant objects x to be uploaded to the server