2017-09-26 03:09:19 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This file contains some re-usable predictors for auto-complete. The
|
|
|
|
// command-specific autocomplete configurations live within each command's
|
|
|
|
// own source file, as AutocompleteArgs and AutocompleteFlags methods on each
|
|
|
|
// Command implementation.
|
|
|
|
|
|
|
|
// For completing the value of boolean flags like -foo false
|
|
|
|
var completePredictBoolean = complete.PredictSet("true", "false")
|
|
|
|
|
|
|
|
// We don't currently have a real predictor for module sources, but
|
|
|
|
// we'll probably add one later.
|
|
|
|
var completePredictModuleSource = complete.PredictAnything
|
2017-09-26 03:59:29 +02:00
|
|
|
|
|
|
|
type completePredictSequence []complete.Predictor
|
|
|
|
|
|
|
|
func (s completePredictSequence) Predict(a complete.Args) []string {
|
2022-01-08 04:41:20 +01:00
|
|
|
// Nested subcommands do not require any placeholder entry for their subcommand name.
|
2017-09-26 03:59:29 +02:00
|
|
|
idx := len(a.Completed)
|
|
|
|
if idx >= len(s) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return s[idx].Predict(a)
|
|
|
|
}
|
2017-09-26 04:00:45 +02:00
|
|
|
|
|
|
|
func (m *Meta) completePredictWorkspaceName() complete.Predictor {
|
|
|
|
return complete.PredictFunc(func(a complete.Args) []string {
|
|
|
|
// There are lot of things that can fail in here, so if we encounter
|
|
|
|
// any error then we'll just return nothing and not support autocomplete
|
|
|
|
// until whatever error is fixed. (The user can't actually see the error
|
|
|
|
// here, but other commands should produce a user-visible error before
|
|
|
|
// too long.)
|
|
|
|
|
|
|
|
// We assume here that we want to autocomplete for the current working
|
|
|
|
// directory, since we don't have enough context to know where to
|
|
|
|
// find any config path argument, and it might be _after_ the argument
|
|
|
|
// we're trying to complete here anyway.
|
|
|
|
configPath, err := ModulePath(nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-28 00:31:05 +02:00
|
|
|
backendConfig, diags := m.loadBackendConfig(configPath)
|
|
|
|
if diags.HasErrors() {
|
2017-09-26 04:00:45 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-28 00:31:05 +02:00
|
|
|
b, diags := m.Backend(&BackendOpts{
|
|
|
|
Config: backendConfig,
|
2017-09-26 04:00:45 +02:00
|
|
|
})
|
2018-03-28 00:31:05 +02:00
|
|
|
if diags.HasErrors() {
|
2017-09-26 04:00:45 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
names, _ := b.Workspaces()
|
2017-09-26 04:00:45 +02:00
|
|
|
return names
|
|
|
|
})
|
|
|
|
}
|