-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform command completions #3960
Changes from 2 commits
f11ddea
fd817b5
c688618
1e7ce69
b32e5ab
d813667
f7b0d43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
function __fish_terraform_needs_command | ||
set cmd (commandline -opc) | ||
if [ (count $cmd) -eq 1 ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idiomatic fish way to do this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is not needed anymore. |
||
return 0 | ||
end | ||
|
||
for arg in $cmd[2..-1] | ||
switch $arg | ||
case '--*' | ||
# ignore global flags | ||
case '*' | ||
return 1 | ||
end | ||
end | ||
return 0 | ||
end | ||
|
||
function __fish_terraform_using_command | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @faho should comment on this since I'm a completion newbie but I thought that functions in general should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I replaced this function with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well...... The issue with custom versions is that they are usually just if test "$cmd[2]" = $argv[1]
return 0
else
return 1
end (and maybe some annoying stuff about how $cmd[1] needs to be the name of the tool, which breaks aliases) However, function __fish_use_subcommand -d "Test if a non-switch argument has been given in the current commandline"
set -l cmd (commandline -poc)
set -e cmd[1]
for i in $cmd
switch $i
case '-*'
continue
end
return 1
end
return 0
end This will break if
e.g. on something like Which is why the git completions have the Currently, I don't know of an easier way to be "fully" correct (you essentially need to recreate the command's argument parsing). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case this should be fine since options alowed before Terraform subcommand don't take any arguments (e.g. |
||
set cmd (commandline -opc) | ||
if [ (count $cmd) -eq 1 ] | ||
return 0 | ||
end | ||
|
||
for arg in $cmd[2..-1] | ||
switch $arg | ||
case '--*' | ||
# ignore global flags | ||
case $argv[1] | ||
return 0 | ||
case '*' | ||
return 1 | ||
end | ||
end | ||
return 1 | ||
end | ||
|
||
# general options | ||
complete -f -c terraform -l version -d 'Print version information' | ||
complete -f -c terraform -l help -d 'Show help' | ||
|
||
### apply | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a apply -d 'Builds or changes infrastructure' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o backup -d 'Path to backup the existing state file' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to my previous comment I believe the current best practice is to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o input -d 'Ask for input for variables if not directly set' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o parallelism -d 'Limit the number of concurrent operations' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o refresh -d 'Update state prior to checking for differences' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o state-out -d 'Path to write state' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o target -d 'Resource to target' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o var -d 'Set a variable in the Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command apply' -o var-file -d 'Set variables from a file' | ||
|
||
### console | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a console -d 'Interactive console for Terraform interpolations' | ||
complete -f -c terraform -n '__fish_terraform_using_command console' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command console' -o var -d 'Set a variable in the Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command console' -o var-file -d 'Set variables from a file' | ||
|
||
### destroy | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a destroy -d 'Destroy Terraform-managed infrastructure' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o backup -d 'Path to backup the existing state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o force -d 'Don\'t ask for input for destroy confirmation' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o parallelism -d 'Limit the number of concurrent operations' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o refresh -d 'Update state prior to checking for differences' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o state-out -d 'Path to write state' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o target -d 'Resource to target' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o var -d 'Set a variable in the Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command destroy' -o var-file -d 'Set variables from a file' | ||
|
||
### env | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a env -d 'Environment management' | ||
complete -f -c terraform -n '__fish_terraform_using_command env' -a list -d 'List environments' | ||
complete -f -c terraform -n '__fish_terraform_using_command env' -a select -d 'Select an environment' | ||
complete -f -c terraform -n '__fish_terraform_using_command env' -a new -d 'Create a new environment' | ||
complete -f -c terraform -n '__fish_terraform_using_command env' -a delete -d 'Delete an existing environment' | ||
|
||
### fmt | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a fmt -d 'Rewrites config files to canonical format' | ||
complete -f -c terraform -n '__fish_terraform_using_command fmt' -o list -d 'List files whose formatting differs' | ||
complete -f -c terraform -n '__fish_terraform_using_command fmt' -o write -d 'Write result to source file' | ||
complete -f -c terraform -n '__fish_terraform_using_command fmt' -o diff -d 'Display diffs of formatting changes' | ||
|
||
### get | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a get -d 'Download and install modules for the configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command get' -o update -d 'Check modules for updates' | ||
complete -f -c terraform -n '__fish_terraform_using_command get' -o no-color -d 'If specified, output won\'t contain any color' | ||
|
||
### graph | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a graph -d 'Create a visual graph of Terraform resources' | ||
complete -f -c terraform -n '__fish_terraform_using_command graph' -o draw-cycles -d 'Highlight any cycles in the graph' | ||
complete -f -c terraform -n '__fish_terraform_using_command graph' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command graph' -o type -d 'Type of graph to output' | ||
|
||
### import | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a import -d 'Import existing infrastructure into Terraform' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o backup -d 'Path to backup the existing state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o config -d 'Path to a directory of configuration files' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o input -d 'Ask for input for variables if not directly set' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o provider -d 'Specific provider to use for import' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o state-out -d 'Path to write state' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o var -d 'Set a variable in the Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command import' -o var-file -d 'Set variables from a file' | ||
|
||
### init | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a init -d 'Initialize a new or existing Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o backend -d 'Configure the backend for this environment' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o backend-config -d 'Backend configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o get -d 'Download modules for this configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o input -d 'Ask for input if necessary' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command init' -o force-copy -d 'Suppress prompts about copying state data' | ||
|
||
### output | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a output -d 'Read an output from a state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command output' -o state -d 'Path to the state file to read' | ||
complete -f -c terraform -n '__fish_terraform_using_command output' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command output' -o module -d 'Return the outputs for a specific module' | ||
complete -f -c terraform -n '__fish_terraform_using_command output' -o json -d 'Print output in JSON format' | ||
|
||
### plan | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a plan -d 'Generate and show an execution plan' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o destroy -d 'Generate a plan to destroy all resources' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o detailed-exitcode -d 'Return detailed exit codes' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o input -d 'Ask for input for variables if not directly set' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o module-depth -d 'Depth of modules to show in the output' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o out -d 'Write a plan file to the given path' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o parallelism -d 'Limit the number of concurrent operations' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o refresh -d 'Update state prior to checking for differences' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o target -d 'Resource to target' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o var -d 'Set a variable in the Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command plan' -o var-file -d 'Set variables from a file' | ||
|
||
### push | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a push -d 'Upload this Terraform module to Atlas to run' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o atlas-address -d 'An alternate address to an Atlas instance' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o upload-modules -d 'Lock modules and upload completely' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o name -d 'Name of the configuration in Atlas' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o token -d 'Access token to use to upload' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o overwrite -d 'Variable keys that should overwrite values in Atlas' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o var -d 'Set a variable in the Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o var-file -d 'Set variables from a file' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o vcs -d 'Upload only files committed to your VCS' | ||
complete -f -c terraform -n '__fish_terraform_using_command push' -o no-color -d 'If specified, output won\'t contain any color' | ||
|
||
### refresh | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a refresh -d 'Update local state file against real resources' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o backup -d 'Path to backup the existing state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o input -d 'Ask for input for variables if not directly set' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o state-out -d 'Path to write state' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o target -d 'Resource to target' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o var -d 'Set a variable in the Terraform configuration' | ||
complete -f -c terraform -n '__fish_terraform_using_command refresh' -o var-file -d 'Set variables from a file' | ||
|
||
### show | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a show -d 'Inspect Terraform state or plan' | ||
complete -f -c terraform -n '__fish_terraform_using_command show' -o module-depth -d 'Depth of modules to show in the output' | ||
complete -f -c terraform -n '__fish_terraform_using_command show' -o no-color -d 'If specified, output won\'t contain any color' | ||
|
||
### taint | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a taint -d 'Manually mark a resource for recreation' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o allow-missing -d 'Succeed even if resource is missing' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o backup -d 'Path to backup the existing state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o module -d 'The module path where the resource lives' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o state-out -d 'Path to write state' | ||
|
||
### untaint | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a untaint -d 'Manually unmark a resource as tainted' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o allow-missing -d 'Succeed even if resource is missing' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o backup -d 'Path to backup the existing state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o lock -d 'Lock the state file when locking is supported' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o lock-timeout -d 'Duration to retry a state lock' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o module -d 'The module path where the resource lives' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o no-color -d 'If specified, output won\'t contain any color' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o state -d 'Path to a Terraform state file' | ||
complete -f -c terraform -n '__fish_terraform_using_command taint' -o state-out -d 'Path to write state' | ||
|
||
### validate | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a validate -d 'Validates the Terraform files' | ||
complete -f -c terraform -n '__fish_terraform_using_command validate' -o no-color -d 'If specified, output won\'t contain any color' | ||
|
||
### version | ||
complete -f -c terraform -n '__fish_terraform_needs_command' -a version -d 'Prints the Terraform version' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general you should use local variables to avoid modifying a global var by the same name; i.e.,
set -l cmd...
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not needed anymore.