From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10829 invoked from network); 23 Feb 2023 20:02:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Feb 2023 20:02:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:From:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=mUcy6zCN8eNV+Wt2i2ZGvHsxQCQftRxCOEe9tesjWgI=; b=kFhKRcE2d4HTTL/KJZCXBB8WuT gMoXnAD1b68MXIX18fUfhWDHgMJYkFabg/SeBa5nnYxmfhfFvCQq87C5rwkjSwOCNLZKBpRM0P5of dvPYsRqLxnDicWS38ToKpSJAsSfUWgepA67IVvBG7QcVYAh/iG3xxUY9WTB/4RepOXW/A3KH5U1iE XOiwtZFWN40rYI4+/Qy6hdsYiysWvJo/r+KLVLE1UvOTucTBHiIjZaoh+vGMLZv5BYuPJcfAzSQhm keKuH69ag7SxXKh4lCsALXHW4AsOjzVmRWHCmOqPR9TDfYkoXaTrHS/SR4gDSTA54yN+VRBJUYv/s uyc7xREA==; Received: by zero.zsh.org with local id 1pVHnY-000CeI-3Z; Thu, 23 Feb 2023 20:02:36 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pVHlw-000CJA-FW; Thu, 23 Feb 2023 20:00:56 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1pVHlv-000PnS-3O for zsh-workers@zsh.org; Thu, 23 Feb 2023 21:00:55 +0100 From: Oliver Kiddle To: Zsh workers Subject: PATCH: completion updates for ansible MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <99164.1677182455.1@hydra> Date: Thu, 23 Feb 2023 21:00:55 +0100 Message-ID: <99165-1677182455.101472@4kUM.nC-Q.FNCe> X-Seq: 51474 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: It seems that the --vault-id and -e/--extra-vars options can be repeated. -e can also be followed by @ and a filename which is the only way I can think of to have vault-encrypted variables but keep the option of not bothering to provide a vault password and have it just skip those tasks that need it. Aside from updating the completion to handle these things, this also covers new options up to ansible 2.13.2 which mostly affects the ansible-config command which has gained an init action. Oliver diff --git a/Completion/Unix/Command/_ansible b/Completion/Unix/Command/_ansible index 2d976b0a0..7b85a58e4 100644 --- a/Completion/Unix/Command/_ansible +++ b/Completion/Unix/Command/_ansible @@ -20,8 +20,10 @@ case $service in ;| ansible|ansible-console|ansible-playbook|ansible-pull) args+=( - '(-K --ask-become-pass)'{-K,--ask-become-pass}'[ask for privilege escalation password]' - '(-k --ask-pass)'{-k,--ask-pass}'[ask for connection password]' + '(-K --ask-become-pass --become-password-file)'{-K,--ask-become-pass}'[ask for privilege escalation password]' + '(-K --ask-become-pass)--become-password-file=[specify file containing become password]:file:_files' + '(-k --ask-pass --connection-password-file)'{-k,--ask-pass}'[ask for connection password]' + '(-k --ask-pass)--connection-password-file=[specify file containing connection password]:file:_files' '--list-hosts[output list of matching hosts]' '(-l --limit)'{-l+,--limit=}'[further limit hosts to an additional pattern]:host subset:->hosts' '(-T --timeout)'{-T+,--timeout=}'[override the connection timeout]:timeout (seconds) [10]' @@ -49,8 +51,8 @@ case $service in ansible|ansible-console|ansible-inventory|ansible-playbook|ansible-pull) args+=( --ask-vault-pass{,word}'[ask for vault password]' - '(-e --extra-vars)'{-e+,--extra-vars=}'[set additional variables]:key=value or YAML/JSON' - '--vault-id=[specify vault identity to use]:vault identity' + \*{-e+,--extra-vars=}'[set additional variables]:key=value, YAML/JSON or @file:->extra-vars' + '*--vault-id=[specify vault identity to use]:vault identity' --vault-pass{,word}-file='[specify vault password file]:vault password file:_files' \*{-i+,--inventory=}'[specify inventory host file or host list]: : _alternative "files\:inventory file\:_files" "hosts\:host\: _sequence _hosts"' @@ -86,15 +88,15 @@ case $service in ) ;; ansible-config) - args+=( - '(-c --config)'{-c+,--config=}'[specify configuration file]:config file:_files' + args=( -A "-*" $args '1:action:(( list\:list\ all\ configuration dump\:show\ the\ current\ settings,\ merge\ specified\ configuration view\:display\ the\ current\ config\ file + init\:create\ initial\ configuration ))' + '*::args:->config' ) - [[ -n $words[(r)dump] ]] && args+=( '--only-changed[only show configuration that is changed from the default]' ) ;; ansible-console) args+=( @@ -103,11 +105,11 @@ case $service in ;; ansible-doc) args+=( - '!--metadata-dump' # "internal testing only" + '!--metadata-dump' '!--no-fail-on-errors' # "internal use only" '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-j,--json}'[change output to json format]' '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-l,--list}'[list available plugins]' '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-F,--list_files}'[show plugin names and their source files without summaries]' - '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-s,--snippet}'[show playbook snippet for specified plugins]' + '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-s,--snippet}'[show playbook snippet for inventory, lookup and module plugins]' '(-l --list -F --list_files -s --snippet -e --entry-point)--metadata-dump[dump json metadata for all plugins]' '(-l --list -F --list_files -s --snippet --metadata-dump -e --entry-point)'{-e+,--entry-point=}'[select the entry point for roles]:entry point' '(-t --type)'{-t+,--type=}'[choose plugin type]:plugin type [module]:(become cache callback cliconf connection httpapi inventory lookup netconf shell vars module strategy role keyword)' @@ -218,18 +220,13 @@ case $state in ;; connect-types) plug=connection - ;& - plugins) - plugvar=_ansible_${plug}_plugins - typeset -ga ${plug} - if zstyle -T ":completion:${curcontext}:plugins" verbose; then - (( ${(P)#plugvar} )) || set -A ${plugvar} \ - ${${(f)"$(_call_program plugins ansible-doc -t $plug -l)"}/ ##/:} - _describe -t plugins "${plug} plugin" $plugvar -M 'r:|.=* r:|=*' && ret=0 + state=plugins + ;; + extra-vars) + if compset -P '@'; then + _files -g "*.(json|yml|yaml|ini)(-.)" && ret=0 else - (( ${(P)#plugvar} )) || set -A ${plugvar} \ - ${${(f)"$(_call_program plugins ansible-doc -t $plug -F)"}%% *} - _wanted plugins expl "${plug} plugin" compadd -M 'r:|.=* r:|=*' -a $plugvar && ret=0 + _message 'key=value, YAML/JSON or @file' fi ;; tags) @@ -237,9 +234,39 @@ case $state in _sequence _wanted tags expl tag compadd - \ ${(s.,.)${(j.,.)${(M)${(f)"$(cat **/*.yml)"}:# #tags:*}#*: }} && ret=0 ;; + config) + ign='' + curcontext="${curcontext%:*}-${words[1]}:" + (( $#words > 3 )) && ign='!' + args=( + "${ign}(-)"{-h,--help}'[display usage information]' + \*{-v,--verbose}'[verbose mode]' + '(-c --config)'{-c+,--config=}'[specify configuration file]:config file:_files' + '(-t --type)'{-t+,--type=}'[filter down to a specific plugin type]:plugin type [base]:(all base become cache callback cliconf connection httpapi inventory lookup netconf shell vars)' + '*:plugin:->plugins' + ) + case $words[1] in + dump) + args+=( + '(--only-changed --changed-only)'{--only-changed,--changed-only}'[only show configuration that is changed from the default]' + ) + ;; + init) + args+=( + '--format=[specify output format for init]:format:(init env vars)' + '--disabled[prefix all entries with a comment character]' + ) + ;; + esac + _arguments -s -S : $args && ret=0 + plug=${(v)opt_args[(i)-(t|-type)]} + [[ $plug = base ]] && state= + ;; galaxy) ign='' gactions=( delete import info init install list remove search setup ) + args=( "${ign}(-)"{-h,--help}'[display usage information]' ) + (( $#words > 3 )) && ign='!' case ${(j.:.)line[1,3]} in (role|collection):*:*) subcmd="${line[1]}-${line[2]}" @@ -253,14 +280,11 @@ case $state in [^:]#) words=( role "$words[@]" ) (( CURRENT++ )) + args=() ;; esac curcontext="${curcontext%:*}-${subcmd}:" - (( $#words > 3 )) && ign='!' - args=( - "${ign}(-)"{-h,--help}'[display usage information]' - '1: :{ _wanted actions expl action compadd -a gactions }' - ) + args+=( '1: :{ _wanted actions expl action compadd -a gactions }' ) case $subcmd in *-*) args+=( @@ -403,4 +427,19 @@ case $state in ;; esac +if [[ $state = plugins ]]; then + [[ -z $plug ]] && return ret + plugvar=_ansible_${plug}_plugins + typeset -ga ${plug} + if zstyle -T ":completion:${curcontext}:plugins" verbose; then + (( ${(P)#plugvar} )) || set -A ${plugvar} \ + ${${(f)"$(_call_program plugins ansible-doc -t $plug -l)"}/ ##/:} + _describe -t plugins "${plug} plugin" $plugvar -M 'r:|.=* r:|=*' && ret=0 + else + (( ${(P)#plugvar} )) || set -A ${plugvar} \ + ${${(f)"$(_call_program plugins ansible-doc -t $plug -F)"}%% *} + _wanted plugins expl "${plug} plugin" compadd -M 'r:|.=* r:|=*' -a $plugvar && ret=0 + fi +fi + return ret