-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
CLI autocomplete #16176
Merged
Merged
CLI autocomplete #16176
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The CLI package has automatic support for shell autocomplete (bash and zsh, at time of writing) for subcommands, so all we need to do here is just opt into it. Users can install this into their shells by running: terraform -install-autocomplete
We use boolean flags and module sources in a lot of places, so we'll define global predictors for these which we can use across many commands.
The predictors built in to the "complete" package assume that the same type of argument is repeated indefinitely, but most Terraform commands don't work like that, so this helper allows us to define a sequence of predictors that apply to each argument in turn.
This helper is a Predictor for the "complete" package that tries to auto-complete workspace names from the current backend, if it's initialized and operable.
Shell tab completion for all of the subcommands under "terraform workspace", providing the appropriate kind of auto-complete for each argument, along with completion for for any flags.
jbardin
approved these changes
Sep 26, 2017
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
ghost
locked and limited conversation to collaborators
Apr 5, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This set of changes enables tab-completion for
bash
andzsh
users, building on the mechanisms provided by thecli
package, which in turn delegates to thecomplete
package.By turning on autocomplete, we get autocomplete of the sub-command names themselves for free.
We then need to augment each command object with some additional methods to define the expected options and arguments. This changeset does this for
terraform init
and for theterraform workspace ...
family of commands. We can build out comprehensive support across all the commands over time in separate PRs.