Skip to content
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

Merged
merged 7 commits into from Apr 17, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions share/completions/terraform.fish
@@ -0,0 +1,74 @@
function __fish_terraform_needs_command
set cmd (commandline -opc)
Copy link
Contributor

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....

Copy link
Contributor Author

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.

if [ (count $cmd) -eq 1 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idiomatic fish way to do this is if not set -q cmd[2] to avoid the subcommand and test. Also, we prefer test over [. The latter is there strictly to make it easier for people transitioning from POSIX 1003.1 shells.

Copy link
Contributor Author

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.

return 0
end

for arg in $cmd[2..-1]
switch $arg
case '--*'
# ignore global flags
case '*'
return 1
end
end
return 0
end

# general options
complete -f -c terraform -n '__fish_terraform_needs_command' -l version -d 'Print version information'
complete -f -c terraform -n '__fish_terraform_needs_command' -l help -d 'Show help'

### apply
complete -f -c terraform -n '__fish_terraform_needs_command' -a apply -d 'Builds or changes infrastructure'

### console
complete -f -c terraform -n '__fish_terraform_needs_command' -a console -d 'Interactive console for Terraform interpolations'

### destroy
complete -f -c terraform -n '__fish_terraform_needs_command' -a destroy -d 'Destroy Terraform-managed infrastructure'

### env
complete -f -c terraform -n '__fish_terraform_needs_command' -a env -d 'Environment management'

### fmt
complete -f -c terraform -n '__fish_terraform_needs_command' -a fmt -d 'Rewrites config files to canonical format'

### get
complete -f -c terraform -n '__fish_terraform_needs_command' -a get -d 'Download and install modules for the configuration'

### graph
complete -f -c terraform -n '__fish_terraform_needs_command' -a graph -d 'Create a visual graph of Terraform resources'

### import
complete -f -c terraform -n '__fish_terraform_needs_command' -a import -d 'Import existing infrastructure into Terraform'

### init
complete -f -c terraform -n '__fish_terraform_needs_command' -a init -d 'Initialize a new or existing Terraform configuration'

### output
complete -f -c terraform -n '__fish_terraform_needs_command' -a output -d 'Read an output from a state file'

### plan
complete -f -c terraform -n '__fish_terraform_needs_command' -a plan -d 'Generate and show an execution plan'

### push
complete -f -c terraform -n '__fish_terraform_needs_command' -a push -d 'Upload this Terraform module to Atlas to run'

### refresh
complete -f -c terraform -n '__fish_terraform_needs_command' -a refresh -d 'Update local state file against real resources'

### show
complete -f -c terraform -n '__fish_terraform_needs_command' -a show -d 'Inspect Terraform state or plan'

### taint
complete -f -c terraform -n '__fish_terraform_needs_command' -a taint -d 'Manually mark a resource for recreation'

### untaint
complete -f -c terraform -n '__fish_terraform_needs_command' -a untaint -d 'Manually unmark a resource as tainted'

### validate
complete -f -c terraform -n '__fish_terraform_needs_command' -a validate -d 'Validates the Terraform files'

### version
complete -f -c terraform -n '__fish_terraform_needs_command' -a version -d 'Prints the Terraform version'