mirror of
https://github.com/hashicorp/terraform.git
synced 2026-04-21 14:18:43 -04:00
Some checks are pending
build / Determine intended Terraform version (push) Waiting to run
build / Determine Go toolchain version (push) Waiting to run
build / Generate release metadata (push) Blocked by required conditions
build / Build for freebsd_386 (push) Blocked by required conditions
build / Build for linux_386 (push) Blocked by required conditions
build / Build for openbsd_386 (push) Blocked by required conditions
build / Build for windows_386 (push) Blocked by required conditions
build / Build for darwin_amd64 (push) Blocked by required conditions
build / Build for freebsd_amd64 (push) Blocked by required conditions
build / Build for linux_amd64 (push) Blocked by required conditions
build / Build for openbsd_amd64 (push) Blocked by required conditions
build / Build for solaris_amd64 (push) Blocked by required conditions
build / Build for windows_amd64 (push) Blocked by required conditions
build / Build for freebsd_arm (push) Blocked by required conditions
build / Build for linux_arm (push) Blocked by required conditions
build / Build for darwin_arm64 (push) Blocked by required conditions
build / Build for linux_arm64 (push) Blocked by required conditions
build / Build for windows_arm64 (push) Blocked by required conditions
build / Build Docker image for linux_386 (push) Blocked by required conditions
build / Build Docker image for linux_amd64 (push) Blocked by required conditions
build / Build Docker image for linux_arm (push) Blocked by required conditions
build / Build Docker image for linux_arm64 (push) Blocked by required conditions
build / Build e2etest for linux_386 (push) Blocked by required conditions
build / Build e2etest for windows_386 (push) Blocked by required conditions
build / Build e2etest for darwin_amd64 (push) Blocked by required conditions
build / Build e2etest for linux_amd64 (push) Blocked by required conditions
build / Build e2etest for windows_amd64 (push) Blocked by required conditions
build / Build e2etest for linux_arm (push) Blocked by required conditions
build / Build e2etest for darwin_arm64 (push) Blocked by required conditions
build / Build e2etest for linux_arm64 (push) Blocked by required conditions
build / Run e2e test for linux_386 (push) Blocked by required conditions
build / Run e2e test for windows_386 (push) Blocked by required conditions
build / Run e2e test for darwin_amd64 (push) Blocked by required conditions
build / Run e2e test for linux_amd64 (push) Blocked by required conditions
build / Run e2e test for windows_amd64 (push) Blocked by required conditions
build / Run e2e test for linux_arm (push) Blocked by required conditions
build / Run e2e test for linux_arm64 (push) Blocked by required conditions
build / Run terraform-exec test for linux amd64 (push) Blocked by required conditions
Quick Checks / Unit Tests (push) Waiting to run
Quick Checks / Race Tests (push) Waiting to run
Quick Checks / End-to-end Tests (push) Waiting to run
Quick Checks / Code Consistency Checks (push) Waiting to run
* Add a generic method for loading an operations backend in non-init commands * Refactor commands to use new prepareBackend method: group 1 * Refactor commands to use new prepareBackend method: group 2, where config parsing needs to be explicitly added * Refactor commands to use new prepareBackend method: group 3, where we can use already parsed config * Additional, more nested, places where logic for accessing backends needs to be refactored * Remove duplicated comment * Add test coverage of `(m *Meta) prepareBackend()` * Add TODO related to using plans for backend/state_store config in apply commands * Add `testStateStoreMockWithChunkNegotiation` test helper * Add assertions to tests about the backend (remote-state, local, etc) in use within operations backend * Stop prepareBackend taking locks as argument * Code comment in prepareBackend * Replace c.Meta.prepareBackend with c.prepareBackend * Change `c.Meta.loadSingleModule` to `c.loadSingleModule` * Rename (Meta).prepareBackend to (Meta).backend, update godoc comment to make relationship to (Meta).Backend more obvious. * Revert change from config.Module to config.Root.Module * Update `(m *Meta) backend` method to parse config itself, and also to adhere to calling code's viewtype instructions * Update all tests and calling code following previous commit * Change how an operations backend is obtained by autocomplete code * Update autocomplete to return nil if no workspace names are returned from the backend * Add test coverage for autocompleting workspace names when using a pluggable state store * Fix output command: pass view type data to new `backend` method * Fix in plan command: pass correct view type to `backend` method * Fix `providers schema` command to use correct viewtype when preparing a backend
66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package command
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/internal/command/arguments"
|
|
"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
|
|
|
|
type completePredictSequence []complete.Predictor
|
|
|
|
func (s completePredictSequence) Predict(a complete.Args) []string {
|
|
// Nested subcommands do not require any placeholder entry for their subcommand name.
|
|
idx := len(a.Completed)
|
|
if idx >= len(s) {
|
|
return nil
|
|
}
|
|
|
|
return s[idx].Predict(a)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
b, diags := m.backend(configPath, arguments.ViewHuman)
|
|
if diags.HasErrors() {
|
|
return nil
|
|
}
|
|
|
|
names, _ := b.Workspaces()
|
|
if len(names) == 0 {
|
|
// Presence of the "default" isn't always guaranteed
|
|
// Backends will report it as always existing, pluggable
|
|
// state stores will only do so if it _actually_ exists.
|
|
return nil
|
|
}
|
|
return names
|
|
})
|
|
}
|