1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-02-12 05:49:47 +08:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Carlo Sala
fd01fd66ce
perf(nvm): don't call nvm version on every cd
Now we only call `nvm version` in case we changed directory and we are
not anymore in a `.nvmrc` directory.
See https://github.com/nvm-sh/nvm/pull/2874
2024-03-04 11:11:35 +01:00
Carlo Sala
94aa49c0b9
feat(nvm)!: make lazy and autoload options compatible
BREAKING CHANGE: Prior to this commit, if `lazy` and `autoload` options
were enabled at the same time, `lazy` was getting overriden and only
`autoload` was taken into account.
Now they work together and `autoload` will be enabled after `nvm` has
been lazy-loaded.

Closes #11690
2024-03-04 11:11:27 +01:00
Carlo Sala
0ea0d14288
fix(nvm): remove zsh completion
We rely on official bash completion now on.
2024-03-04 10:47:34 +01:00
Maxime Brunet
da16258c5c
fix(terraform): fix completion repeating flags with value (#12256) 2024-03-04 08:28:00 +01:00
Maxime Brunet
f17aa2ffa8
fix(terraform): pass -chdir to completion commands (#12254) 2024-03-03 21:22:41 +01:00
4 changed files with 181 additions and 192 deletions

View File

@ -43,8 +43,7 @@ zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ...
#### `.nvmrc` autoload
Note: _this option cannot be used at the same time as `lazy`. `autoload` will override it and load `nvm` at
startup._
Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_
If set, the plugin will automatically load a node version when if finds a
[`.nvmrc` file](https://github.com/nvm-sh/nvm#nvmrc) in the current working directory indicating which node

View File

@ -1,34 +0,0 @@
#compdef nvm
#autoload
[[ -f "$NVM_DIR/nvm.sh" ]] || return 0
local -a _1st_arguments
_1st_arguments=(
'help:show help'
'--version:print out the latest released version of nvm'
'install:download and install a version in <node|iojs|node version number>'
'install-latest-npm:download and install the latest npm version'
'uninstall:uninstall a version'
'use:modify PATH to use <version>. Uses .nvmrc if available'
'exec:run <command> on <version>. Uses .nvmrc if available'
'run:run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
'current:list installed versions'
'ls:list installed versions or versions matching a given description'
'version:resolve the given description to a single local version'
'version-remote:resolve the given description to a single remote version'
'ls-remote:list remote versions available for install'
'deactivate:undo effects of `nvm` on current shell'
'alias:show or set aliases'
'unalias:deletes an alias'
'reinstall-packages:reinstall global `npm` packages contained in <version> to current version'
'unload:unload `nvm` from shell'
'which:display path to installed node version. Uses .nvmrc if available'
)
_arguments -C '*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "nvm subcommand" _1st_arguments
return
fi

View File

@ -1,3 +1,7 @@
# Don't try to load nvm if command already available
# Note: nvm is a function so we need to use `which`
which nvm &>/dev/null && return
# See https://github.com/nvm-sh/nvm#installation-and-update
if [[ -z "$NVM_DIR" ]]; then
if [[ -d "$HOME/.nvm" ]]; then
@ -12,41 +16,35 @@ if [[ -z "$NVM_DIR" ]]; then
fi
fi
# Don't try to load nvm if command already available
# Note: nvm is a function so we need to use `which`
which nvm &>/dev/null && return
if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then
return
fi
if zstyle -t ':omz:plugins:nvm' lazy && \
! zstyle -t ':omz:plugins:nvm' autoload; then
# Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
nvm_lazy_cmd=(nvm node npm npx pnpm yarn $nvm_lazy_cmd) # default values
eval "
function $nvm_lazy_cmd {
for func in $nvm_lazy_cmd; do
if (( \$+functions[\$func] )); then
unfunction \$func
fi
done
# Load nvm if it exists in \$NVM_DIR
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
\"\$0\" \"\$@\"
}
"
unset nvm_lazy_cmd
else
source "$NVM_DIR/nvm.sh"
fi
function _omz_load_nvm_completion {
local _nvm_completion
# Load nvm bash completion
for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
if [[ -f "$_nvm_completion" ]]; then
# Load bashcompinit
autoload -U +X bashcompinit && bashcompinit
# Bypass compinit call in nvm bash completion script. See:
# https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93
ZSH_VERSION= source "$_nvm_completion"
break
fi
done
unfunction _omz_load_nvm_completion
}
# Autoload nvm when finding a .nvmrc file in the current directory
# Adapted from: https://github.com/nvm-sh/nvm#zsh
if zstyle -t ':omz:plugins:nvm' autoload; then
function _omz_setup_autoload {
if ! zstyle -t ':omz:plugins:nvm' autoload; then
unfunction _omz_setup_autoload
return
fi
# Autoload nvm when finding a .nvmrc file in the current directory
# Adapted from: https://github.com/nvm-sh/nvm#zsh
function load-nvmrc {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
local nvm_silent=""
zstyle -t ':omz:plugins:nvm' silent-autoload && nvm_silent="--silent"
@ -59,10 +57,8 @@ if zstyle -t ':omz:plugins:nvm' autoload; then
elif [[ "$nvmrc_node_version" != "$node_version" ]]; then
nvm use $nvm_silent
fi
elif [[ "$node_version" != "$(nvm version default)" ]]; then
if [[ -z $nvm_silent ]]; then
echo "Reverting to nvm default version"
fi
elif [[ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ]] && [[ "$(nvm version)" != "$(nvm version default)" ]]; then
[[ -z $nvm_silent ]] && echo "Reverting to nvm default version"
nvm use default $nvm_silent
fi
@ -72,18 +68,30 @@ if zstyle -t ':omz:plugins:nvm' autoload; then
add-zsh-hook chpwd load-nvmrc
load-nvmrc
unfunction _omz_setup_autoload
}
if zstyle -t ':omz:plugins:nvm' lazy; then
# Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
nvm_lazy_cmd=(nvm node npm npx pnpm yarn $nvm_lazy_cmd) # default values
eval "
function $nvm_lazy_cmd {
for func in $nvm_lazy_cmd; do
if (( \$+functions[\$func] )); then
unfunction \$func
fi
done
# Load nvm if it exists in \$NVM_DIR
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
_omz_load_nvm_completion
_omz_setup_autoload
\"\$0\" \"\$@\"
}
"
unset nvm_lazy_cmd
else
source "$NVM_DIR/nvm.sh"
_omz_load_nvm_completion
_omz_setup_autoload
fi
# Load nvm bash completion
for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
if [[ -f "$nvm_completion" ]]; then
# Load bashcompinit
autoload -U +X bashcompinit && bashcompinit
# Bypass compinit call in nvm bash completion script. See:
# https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93
ZSH_VERSION= source "$nvm_completion"
break
fi
done
unset NVM_HOMEBREW nvm_completion

View File

@ -29,7 +29,7 @@ compdef _terraform terraform
'version:Show the current Terraform version'
'workspace:Workspace management'
)
if ((CURRENT == 1)); then
if (( CURRENT == 1 )); then
_describe -t commands 'terraform commands' _terraform_cmds
return
fi
@ -38,6 +38,8 @@ compdef _terraform terraform
cmd="${${_terraform_cmds[(r)$words[1]:*]%%:*}}"
curcontext="${curcontext%:*:*}:terraform-${cmd}:"
local __chdir="${opt_args[-chdir]:-.}"
if (( ${+functions[_terraform_$cmd]} )); then
"_terraform_${cmd}"
else
@ -48,48 +50,48 @@ compdef _terraform terraform
(( ${+functions[_terraform_apply]} )) || _terraform_apply() {
_arguments \
'-auto-approve[Skip interactive approval of plan before applying.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -W __chdir -g "*.backup"' \
'-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
'-destroy[Destroy Terraform-managed infrastructure. The command "terraform destroy" is a convenience alias for this option.]' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
'-no-color[If specified, output won'\''t contain any color.]' \
'-parallelism=[(10) Limit the number of parallel resource operations.]' \
'-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \
'-refresh=[(true) Skip checking for external changes to remote objects while creating the plan. This can potentially make planning faster, but at the expense of possibly planning against a stale record of the remote system state.]:refresh:(true false)' \
'*-replace=[(resource) Force replacement of a particular resource instance using its resource address. If applying would'\''ve normally produced an update or no-op action for this instance, Terraform will replace it instead. You can use this option multiple times to replace more than one object.]:resource:__terraform_state_resources' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -W __chdir -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -W __chdir -g "*.tfstate"' \
'*-target=[(resource) Limit the operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -g "*.tfvars{,.json}"' \
':plan:_files -'
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' \
':plan:_files -W __chdir -'
}
(( ${+functions[_terraform_console]} )) || _terraform_console() {
_arguments \
'-state=[(terraform.tfstate) Legacy option for the local backend only. See the local backend'\''s documentation for more information.]' \
'-state=[(terraform.tfstate) Legacy option for the local backend only. See the local backend'\''s documentation for more information.]:statefile:_files -W __chdir -g "*.tfstate"' \
'-plan[Create a new plan (as if running "terraform plan") and then evaluate expressions against its planned state, instead of evaluating against the current state. You can use this to inspect the effects of configuration changes that haven'\''t been applied yet.]' \
'*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
'*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]:var:' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -W __chdir -g "*.tfvars{,.json}"'
}
(( ${+functions[_terraform_destroy]} )) || _terraform_destroy() {
_arguments \
'-auto-approve[Skip interactive approval of plan before applying.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -W __chdir -g "*.backup"' \
'-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
'-no-color[If specified, output won'\''t contain any color.]' \
'-parallelism=[(10) Limit the number of parallel resource operations.]' \
'-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \
'-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]:refresh:(true false)' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -W __chdir -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -W __chdir -g "*.tfstate"' \
'*-target=[(resource) Limit the operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -g "*.tfvars{,.json}"'
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"'
}
(( ${+functions[_terraform_fmt]} )) || _terraform_fmt() {
@ -100,7 +102,7 @@ compdef _terraform terraform
'-check[Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.]' \
'-no-color[If specified, output won'\''t contain any color.]' \
'-recursive[Also process files in subdirectories. By default, only the given directory (or current directory) is processed.]' \
'*:targets:_files -'
'*:targets:_files -W __chdir -'
}
(( ${+functions[_terraform_force-unlock]} )) || _terraform_force-unlock() {
@ -113,29 +115,29 @@ compdef _terraform terraform
_arguments \
'-update[Check already-downloaded modules for available updates and install the newest versions available.]' \
'-no-color[Disable text coloring in the output.]' \
'-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -/'
'-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/'
}
(( ${+functions[_terraform_graph]} )) || _terraform_graph() {
_arguments \
'-draw-cycles[Highlight any cycles in the graph with colored edges. This helps when diagnosing cycle errors. This option is supported only when illustrating a real evaluation graph, selected using the -type=TYPE option.]' \
'-module-depth=[(-1) (deprecated) In prior versions of Terraform, specified the depth of modules to show in the output.]' \
'-plan=[Render graph using the specified plan file instead of the configuration in the current directory. Implies -type=apply.]:plan:_files -' \
'-module-depth=[(-1) (deprecated) In prior versions of Terraform, specified the depth of modules to show in the output.]:module_depth:' \
'-plan=[Render graph using the specified plan file instead of the configuration in the current directory. Implies -type=apply.]:plan:_files -W __chdir -' \
'-type=[(plan) Type of operation graph to output. Can be: plan, plan-refresh-only, plan-destroy, or apply. By default Terraform just summarizes the relationships between the resources in your configuration, without any particular operation in mind. Full operation graphs are more detailed but therefore often harder to read.]:type:(plan plan-refresh-only plan-destroy apply)'
}
(( ${+functions[_terraform_import]} )) || _terraform_import() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-config=[(path) Path to a directory of Terraform configuration files to use to configure the provider. Defaults to pwd. If no config files are present, they must be provided via the input prompts or env vars.]:config:_files -/' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -W __chdir -g "*.backup"' \
'-config=[(path) Path to a directory of Terraform configuration files to use to configure the provider. Defaults to pwd. If no config files are present, they must be provided via the input prompts or env vars.]:config:_files -W __chdir -/' \
'-input=[(true) Disable interactive input prompts.]:input:(true false)' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-no-color[If specified, output will contain no color.]' \
'-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
'-state-out=[(PATH) Path to the destination state file to write to. If this is not specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -g "*.tfstate"' \
'*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times. This is only useful with the "-config" flag.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"' \
'-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -g "*.tfstate"' \
'-state-out=[(PATH) Path to the destination state file to write to. If this is not specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -W __chdir -g "*.tfstate"' \
'*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times. This is only useful with the "-config" flag.]:var:' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -W __chdir -g "*.tfvars{,.json}"' \
':addr:' \
':id:'
}
@ -143,21 +145,21 @@ compdef _terraform terraform
(( ${+functions[_terraform_init]} )) || _terraform_init() {
_arguments \
'-backend=[(true) Disable backend or Terraform Cloud initialization for this configuration and use what was previously initialized instead.]:backend:(true false)' \
'-backend-config=[Configuration to be merged with what is in the configuration file'\''s '\''backend'\'' block. This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a '\''key=value'\'' format, and can be specified multiple times. The backend type must be in the configuration itself.]:backend_config:_files -' \
'-backend-config=[Configuration to be merged with what is in the configuration file'\''s '\''backend'\'' block. This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a '\''key=value'\'' format, and can be specified multiple times. The backend type must be in the configuration itself.]:backend_config:_files -W __chdir -' \
'-force-copy[Suppress prompts about copying state data. This is equivalent to providing a "yes" to all confirmation prompts.]' \
'-from-module=[Copy the contents of the given module into the target directory before initialization.]:from_module:_files -/' \
'-from-module=[Copy the contents of the given module into the target directory before initialization.]:from_module:_files -W __chdir -/' \
'-get=[(true) Disable downloading modules for this configuration.]:get:(true false)' \
'-input=[(true) Disable interactive prompts. Note that some actions may require interactive prompts and will error if input is disabled.]:input:(true false)' \
'-lock=[(true) Don'\''t hold a state lock during backend migration. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-no-color[If specified, output will contain no color.]' \
'-plugin-dir[Directory containing plugin binaries. This overrides all default search paths for plugins, and prevents the automatic installation of plugins. This flag can be used multiple times.]:plugin_dir:_files -/' \
'-plugin-dir[Directory containing plugin binaries. This overrides all default search paths for plugins, and prevents the automatic installation of plugins. This flag can be used multiple times.]:plugin_dir:_files -W __chdir -/' \
'-reconfigure[Reconfigure the backend, ignoring any saved configuration.]' \
'-migrate-state[Reconfigure a backend, and attempt to migrate any existing state.]' \
'-upgrade[Install the latest module and provider versions allowed within configured constraints, overriding the default behavior of selecting exactly the version recorded in the dependency lockfile.]' \
'-lockfile=[Set a dependency lockfile mode. Currently only "readonly" is valid.]:lockfile:( readonly )' \
'-ignore-remote-version[A rare option used for Terraform Cloud and the remote backend only. Set this to ignore checking that the local and remote Terraform versions use compatible state representations, making an operation proceed even when there is a potential mismatch. See the documentation on configuring Terraform with Terraform Cloud for more information.]' \
'-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -/'
'-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/'
}
(( ${+functions[_terraform_login]} )) || _terraform_login() {
@ -171,17 +173,22 @@ compdef _terraform terraform
}
(( ${+functions[_terraform_metadata]} )) || _terraform_metadata() {
_arguments \
'*::terraform metadata command:_terraform_metadata_commands'
}
(( ${+functions[_terraform_metadata_commands]} )) || _terraform_metadata_commands() {
local -a _metadata_cmds
_metadata_cmds=(
'functions:Show signatures and descriptions for the available functions'
)
if [[ "${CURRENT}" -lt 3 ]]; then
if (( CURRENT == 1 )); then
_describe -t commands "terraform metadata commands" _metadata_cmds
return
fi
local curcontext="${curcontext}"
cmd="${${_metadata_cmds[(r)$words[2]:*]%%:*}}"
cmd="${${_metadata_cmds[(r)$words[1]:*]%%:*}}"
curcontext="${curcontext%:*:*}:terraform-metadata-${cmd}:"
if (( ${+functions[_terraform_metadata_$cmd]} )); then
@ -193,13 +200,12 @@ compdef _terraform terraform
(( ${+functions[_terraform_metadata_functions]} )) || _terraform_metadata_functions() {
_arguments \
'-json' \
'::'
'-json[]'
}
(( ${+functions[_terraform_output]} )) || _terraform_output() {
_arguments \
'-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate". Ignored when remote state is used.]:statefile:_files -g "*.tfstate"' \
'-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate". Ignored when remote state is used.]:statefile:_files -W __chdir -g "*.tfstate"' \
'-no-color[If specified, output will contain no color.]' \
'-json[If specified, machine readable output will be printed in JSON format]' \
'-raw[For value types that can be automatically converted to a string, will print the raw string directly, rather than a human-oriented representation of the value.]' \
@ -212,40 +218,41 @@ compdef _terraform terraform
'-destroy[Select the "destroy" planning mode, which creates a plan to destroy all objects currently managed by this Terraform configuration instead of the usual behavior.]' \
'-detailed-exitcode[Return detailed exit codes when the command exits. This will change the meaning of exit codes to: 0 - Succeeded, diff is empty (no changes); 1 - Errored, 2 - Succeeded; there is a diff]' \
'-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
'-generate-config-out=[(path) (Experimental) If import blocks are present in configuration, instructs Terraform to generate HCL for any imported resources not already present. The configuration is written to a new file at PATH, which must not already exist. Terraform may still attempt to write configuration if the plan errors.]' \
'-generate-config-out=[(path) (Experimental) If import blocks are present in configuration, instructs Terraform to generate HCL for any imported resources not already present. The configuration is written to a new file at PATH, which must not already exist. Terraform may still attempt to write configuration if the plan errors.]:generate_config_out:' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-no-color[If specified, output will contain no color.]' \
'-out=[(path) Write a plan file to the given path. This can be used as input to the "apply" command.]' \
'-parallelism=[(10) Limit the number of concurrent operations.]' \
'-out=[(path) Write a plan file to the given path. This can be used as input to the "apply" command.]:out:' \
'-parallelism=[(10) Limit the number of concurrent operations.]:parallelism:' \
'-refresh=[(true) Skip checking for external changes to remote objects while creating the plan. This can potentially make planning faster, but at the expense of possibly planning against a stale record of the remote system state.]:refresh:(true false)' \
'-refresh-only[Select the "refresh only" planning mode, which checks whether remote objects still match the outcome of the most recent Terraform apply but does not propose any actions to undo any changes made outside of Terraform.]' \
'*-replace=[(resource) Force replacement of a particular resource instance using its resource address. If the plan would'\''ve normally produced an update or no-op action for this instance, Terraform will plan to replace it instead. You can use this option multiple times to replace more than one object.]:replace:__terraform_state_resources' \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -g "*.tfstate"' \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -W __chdir -g "*.tfstate"' \
'*-target=[(resource) Limit the planning operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -g "*.tfvars{,.json}"'
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"'
}
(( ${+functions[_terraform_providers]} )) || _terraform_providers() {
_arguments \
'-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \
'*::terraform providers command:_terraform_providers_commands'
}
(( ${+functions[_terraform_providers_commands]} )) || _terraform_providers_commands() {
local -a _providers_cmds
_providers_cmds=(
'lock:Write out dependency locks for the configured providers'
'mirror:Save local copies of all required provider plugins'
'schema:Show schemas for the providers used in the configuration'
)
if [[ "${CURRENT}" -lt 3 ]]; then
_arguments \
'-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -/' \
'*:: :->command'
if (( CURRENT == 1 )); then
_describe -t commands "terraform providers commands" _providers_cmds
return
fi
local curcontext="${curcontext}"
cmd="${${_providers_cmds[(r)$words[2]:*]%%:*}}"
cmd="${${_providers_cmds[(r)$words[1]:*]%%:*}}"
curcontext="${curcontext%:*:*}:terraform-providers-${cmd}:"
if (( ${+functions[_terraform_providers_$cmd]} )); then
@ -257,49 +264,53 @@ compdef _terraform terraform
(( ${+functions[_terraform_providers_lock]} )) || _terraform_providers_lock() {
_arguments \
'-fs-mirror=[(dir) Consult the given filesystem mirror directory instead of the origin registry for each of the given providers.]:fs_mirror:_files -/' \
'-net-mirror=[(url) Consult the given network mirror (given as a base URL) instead of the origin registry for each of the given providers.]' \
'*-platform=[(os_arch) Choose a target platform to request package checksums for.]' \
'-fs-mirror=[(dir) Consult the given filesystem mirror directory instead of the origin registry for each of the given providers.]:fs_mirror:_files -W __chdir -/' \
'-net-mirror=[(url) Consult the given network mirror (given as a base URL) instead of the origin registry for each of the given providers.]:net_mirror:' \
'*-platform=[(os_arch) Choose a target platform to request package checksums for.]:platform:' \
'*:provider:'
}
(( ${+functions[_terraform_providers_mirror]} )) || _terraform_providers_mirror() {
_arguments \
'*-platform=[(os_arch) Choose which target platform to build a mirror for.]' \
'*-platform=[(os_arch) Choose which target platform to build a mirror for.]:platform:' \
'::' \
':target_dir:_files -/'
':target_dir:_files -W __chdir -/'
}
(( ${+functions[_terraform_providers_schema]} )) || _terraform_providers_schema() {
_arguments \
'-json[]' \
'::'
'-json[]'
}
(( ${+functions[_terraform_refresh]} )) || _terraform_refresh() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]::backupfile:_files -g "*.backup"' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]::backupfile:_files -W __chdir -g "*.backup"' \
'-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
'-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-no-color[If specified, output will not contain any color.]' \
'-parallelism=[(10) Limit the number of parallel resource operations.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
'-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -W __chdir -g "*.tfstate"' \
'*-target=[(resource) A Resource Address to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__terraform_state_resources' \
'*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
'*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]:var:' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -W __chdir -g "*.tfvars{,.json}"'
}
(( ${+functions[_terraform_show]} )) || _terraform_show() {
_arguments \
'-json[If specified, output the Terraform plan or state in a machine-readable form.]' \
'-no-color[If specified, output will not contain any color.]' \
':path:_files -g "*.tfstate"'
':path:_files -W __chdir -g "*.tfstate"'
}
(( ${+functions[_terraform_state]} )) || _terraform_state() {
_arguments \
'*::terraform state command:_terraform_state_commands'
}
(( ${+functions[_terraform_state_commands]} )) || _terraform_state_commands() {
local -a _state_cmds
_state_cmds=(
'list:List resources in the state'
@ -310,13 +321,13 @@ compdef _terraform terraform
'rm:Remove instances from the state'
'show:Show a resource in the state'
)
if [[ "${CURRENT}" -lt 3 ]]; then
if (( CURRENT == 1 )); then
_describe -t commands "terraform state commands" _state_cmds
return
fi
local curcontext="${curcontext}"
cmd="${${_state_cmds[(r)$words[2]:*]%%:*}}"
cmd="${${_state_cmds[(r)$words[1]:*]%%:*}}"
curcontext="${curcontext%:*:*}:terraform-state-${cmd}:"
if (( ${+functions[_terraform_state_$cmd]} )); then
@ -328,21 +339,21 @@ compdef _terraform terraform
(( ${+functions[_terraform_state_list]} )) || _terraform_state_list() {
_arguments \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default, Terraform will consult the state of the currently-selected workspace.]:statefile:_files -g "*.tfstate"' \
'-id=[(id) Filters the results to include only instances whose resource types have an attribute named id whose value equals the given id string.]' \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default, Terraform will consult the state of the currently-selected workspace.]:statefile:_files -W __chdir -g "*.tfstate"' \
'-id=[(id) Filters the results to include only instances whose resource types have an attribute named id whose value equals the given id string.]:id:' \
'*:address:__terraform_state_resources'
}
(( ${+functions[_terraform_state_mv]} )) || _terraform_state_mv() {
_arguments \
'-dry-run[If set, prints out what would'\''ve been moved but doesn'\''t actually move anything.]' \
'-backup=[(PATH) Path where Terraform should write the backup for the original state. This can"t be disabled. If not set, Terraform will write it to the same path as the statefile with a ".backup" extension.]:backupfile:_files -g "*.backup"' \
'-backup-out=[(PATH) Path where Terraform should write the backup for the destination state. This can"t be disabled. If not set, Terraform will write it to the same path as the destination state file with a backup extension. This only needs to be specified if -state-out is set to a different path than -state.]:backupfile:_files -g "*.backup"' \
'-backup=[(PATH) Path where Terraform should write the backup for the original state. This can"t be disabled. If not set, Terraform will write it to the same path as the statefile with a ".backup" extension.]:backupfile:_files -W __chdir -g "*.backup"' \
'-backup-out=[(PATH) Path where Terraform should write the backup for the destination state. This can"t be disabled. If not set, Terraform will write it to the same path as the destination state file with a backup extension. This only needs to be specified if -state-out is set to a different path than -state.]:backupfile:_files -W __chdir -g "*.backup"' \
'-ignore-remote-version[A rare option used for the remote backend only. See the remote backend documentation for more information.]' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-state=[(path) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to the destination state file to write to. If this isn"t specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -g "*.tfstate"' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-state=[(path) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -g "*.tfstate"' \
'-state-out=[(path) Path to the destination state file to write to. If this isn"t specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -W __chdir -g "*.tfstate"' \
'::' \
':source:__terraform_state_resources' \
':destination: '
@ -352,7 +363,7 @@ compdef _terraform terraform
_arguments \
'-force[Write the state even if lineages don'\''t match or the remote serial is higher.]' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'::' \
':destination:_files'
}
@ -360,10 +371,10 @@ compdef _terraform terraform
(( ${+functions[_terraform_state_replace-provider]} )) || _terraform_state_replace-provider() {
_arguments \
'-auto-approve[Skip interactive approval.]' \
'-backup=[(PATH) Path where Terraform should write the backup for the state file. This can"t be disabled. If not set, Terraform will write it to the same path as the state file with a ".backup" extension.]:backupfile:_files -g "*.backup"' \
'-backup=[(PATH) Path where Terraform should write the backup for the state file. This can"t be disabled. If not set, Terraform will write it to the same path as the state file with a ".backup" extension.]:backupfile:_files -W __chdir -g "*.backup"' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -g "*.tfstate"' \
'::' \
':from_provider_fqn:' \
':to_provider_fqn:'
@ -372,24 +383,24 @@ compdef _terraform terraform
(( ${+functions[_terraform_state_rm]} )) || _terraform_state_rm() {
_arguments \
'-dry-run[If set, prints out what would'\''ve been removed but doesn'\''t actually remove anything.]' \
'-backup=[(PATH) Path where Terraform should write the backup for the original state.]::backupfile:_files -g "*.backup"' \
'-backup=[(PATH) Path where Terraform should write the backup for the original state.]::backupfile:_files -W __chdir -g "*.backup"' \
'-ignore-remote-version[Continue even if remote and local Terraform versions are incompatible. This may result in an unusable workspace, and should be used with extreme caution.]' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-state=[(PATH) Path to the state file to update. Defaults to the current workspace state.]:statefile:_files -g "*.tfstate"' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-state=[(PATH) Path to the state file to update. Defaults to the current workspace state.]:statefile:_files -W __chdir -g "*.tfstate"' \
'*:address:__terraform_state_resources'
}
(( ${+functions[_terraform_state_show]} )) || _terraform_state_show() {
_arguments \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -g "*.tfstate"' \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -W __chdir -g "*.tfstate"' \
"*:address:__terraform_state_resources"
}
(( ${+functions[__terraform_state_resources]} )) || __terraform_state_resources() {
local resource
local -a resources
terraform state list -state="${opt_args[-state]}" 2>/dev/null | while read -r resource; do
terraform -chdir="${__chdir}" state list -state="${opt_args[-state]}" 2>/dev/null | while read -r resource; do
resources+=( "${resource}" )
done
compadd "${@}" - "${resources[@]}"
@ -398,35 +409,35 @@ compdef _terraform terraform
(( ${+functions[_terraform_taint]} )) || _terraform_taint() {
_arguments \
'-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -W __chdir -g "*.backup"' \
'-ignore-remote-version[A rare option used for the remote backend only. See the remote backend documentation for more information.]' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -W __chdir -g "*.tfstate"' \
'*:address:__terraform_state_resources'
}
(( ${+functions[_terraform_test]} )) || _terraform_test() {
_arguments \
'-cloud-run=[(source) If specified, Terraform will execute this test run remotely using Terraform Cloud. You must specify the source of a module registered in a private module registry as the argument to this flag. This allows Terraform to associate the cloud run with the correct Terraform Cloud module and organization.]' \
'*-filter=[(testfile) If specified, Terraform will only execute the test files specified by this flag. You can use this option multiple times to execute more than one test file.]:testfile:_files -g "*.tftest.hcl"' \
'-cloud-run=[(source) If specified, Terraform will execute this test run remotely using Terraform Cloud. You must specify the source of a module registered in a private module registry as the argument to this flag. This allows Terraform to associate the cloud run with the correct Terraform Cloud module and organization.]:cloud_run:' \
'*-filter=[(testfile) If specified, Terraform will only execute the test files specified by this flag. You can use this option multiple times to execute more than one test file.]:testfile:_files -W __chdir -g "*.tftest.hcl"' \
'-json[If specified, machine readable output will be printed in JSON format]' \
'-no-color[If specified, machine readable output will be printed in JSON format]' \
'-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -/' \
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -g "*.tfvars{,.json}"' \
'-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \
'*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
'*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' \
'-verbose[Print the plan or state for each test run block as it executes.]' \
}
(( ${+functions[_terraform_untaint]} )) || _terraform_untaint() {
_arguments \
'-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -W __chdir -g "*.backup"' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -W __chdir -g "*.tfstate"' \
':name:__terraform_state_resources'
}
@ -435,8 +446,8 @@ compdef _terraform terraform
'-json[Produce output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems.]' \
'-no-color[If specified, output will not contain any color.]' \
'-no-tests[If specified, Terraform will not validate test files.]' \
'-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -/' \
':dir:_files -/'
'-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \
':dir:_files -W __chdir -/'
}
(( ${+functions[_terraform_version]} )) || _terraform_version() {
@ -446,6 +457,11 @@ compdef _terraform terraform
}
(( ${+functions[_terraform_workspace]} )) || _terraform_workspace() {
_arguments \
'*::terraform workspace command:_terraform_workspace_commands'
}
(( ${+functions[_terraform_workspace_commands]} )) || _terraform_workspace_commands() {
local -a _workspace_cmds
_workspace_cmds=(
'delete:Delete a workspace'
@ -454,13 +470,13 @@ compdef _terraform terraform
'select:Select a workspace'
'show:Show the name of the current workspace'
)
if [[ "${CURRENT}" -lt 3 ]]; then
if (( CURRENT == 1 )); then
_describe -t commands "terraform workspace commands" _workspace_cmds
return
fi
local curcontext="${curcontext}"
cmd="${${_workspace_cmds[(r)$words[2]:*]%%:*}}"
cmd="${${_workspace_cmds[(r)$words[1]:*]%%:*}}"
curcontext="${curcontext%:*:*}:terraform-workspace-${cmd}:"
if (( ${+functions[_terraform_workspace_$cmd]} )); then
@ -474,7 +490,7 @@ compdef _terraform terraform
_arguments \
'-force[Remove a workspace even if it is managing resources. Terraform can no longer track or manage the workspace'\''s infrastructure.]' \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'::' \
':name:__terraform_workspaces'
}
@ -486,8 +502,8 @@ compdef _terraform terraform
(( ${+functions[_terraform_workspace_new]} )) || _terraform_workspace_new() {
_arguments \
'-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-state=[(path) Copy an existing state file into the new workspace.]:statefile:_files -g "*.tfstate"' \
'-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
'-state=[(path) Copy an existing state file into the new workspace.]:statefile:_files -W __chdir -g "*.tfstate"' \
'::' \
':name:'
}
@ -506,7 +522,7 @@ compdef _terraform terraform
(( ${+functions[__terraform_workspaces]} )) || __terraform_workspaces() {
local workspace
local -a workspaces
terraform workspace list | while read -r workspace; do
terraform -chdir="${__chdir}" workspace list | while read -r workspace; do
if [[ -z "${workspace}" ]]; then
continue
fi
@ -517,7 +533,7 @@ compdef _terraform terraform
_terraform() {
_arguments \
'-chdir=[(DIR) Switch to a different working directory before executing the given subcommand.]:chdir:_files -/' \
'-chdir=[(DIR) Switch to a different working directory before executing the given subcommand.]:chdir:_files -W __chdir -/' \
'-help[Show this help output, or the help for a specified subcommand.]' \
'-version[An alias for the "version" subcommand.]' \
'*::terraform command:_terraform_commands'