mirror of
https://github.com/hashicorp/terraform.git
synced 2026-05-28 04:03:27 -04:00
Some checks failed
build / Determine intended Terraform version (push) Has been cancelled
build / Determine Go toolchain version (push) Has been cancelled
Quick Checks / Unit Tests (push) Has been cancelled
Quick Checks / Race Tests (push) Has been cancelled
Quick Checks / End-to-end Tests (push) Has been cancelled
Quick Checks / Code Consistency Checks (push) Has been cancelled
build / Generate release metadata (push) Has been cancelled
build / Build for freebsd_386 (push) Has been cancelled
build / Build for linux_386 (push) Has been cancelled
build / Build for openbsd_386 (push) Has been cancelled
build / Build for windows_386 (push) Has been cancelled
build / Build for darwin_amd64 (push) Has been cancelled
build / Build for freebsd_amd64 (push) Has been cancelled
build / Build for linux_amd64 (push) Has been cancelled
build / Build for openbsd_amd64 (push) Has been cancelled
build / Build for solaris_amd64 (push) Has been cancelled
build / Build for windows_amd64 (push) Has been cancelled
build / Build for freebsd_arm (push) Has been cancelled
build / Build for linux_arm (push) Has been cancelled
build / Build for darwin_arm64 (push) Has been cancelled
build / Build for linux_arm64 (push) Has been cancelled
build / Build for windows_arm64 (push) Has been cancelled
build / Build Docker image for linux_386 (push) Has been cancelled
build / Build Docker image for linux_amd64 (push) Has been cancelled
build / Build Docker image for linux_arm (push) Has been cancelled
build / Build Docker image for linux_arm64 (push) Has been cancelled
build / Build e2etest for linux_386 (push) Has been cancelled
build / Build e2etest for windows_386 (push) Has been cancelled
build / Build e2etest for darwin_amd64 (push) Has been cancelled
build / Build e2etest for linux_amd64 (push) Has been cancelled
build / Build e2etest for windows_amd64 (push) Has been cancelled
build / Build e2etest for linux_arm (push) Has been cancelled
build / Build e2etest for darwin_arm64 (push) Has been cancelled
build / Build e2etest for linux_arm64 (push) Has been cancelled
build / Run e2e test for linux_386 (push) Has been cancelled
build / Run e2e test for windows_386 (push) Has been cancelled
build / Run e2e test for darwin_amd64 (push) Has been cancelled
build / Run e2e test for linux_amd64 (push) Has been cancelled
build / Run e2e test for windows_amd64 (push) Has been cancelled
build / Run e2e test for linux_arm (push) Has been cancelled
build / Run e2e test for linux_arm64 (push) Has been cancelled
build / Run terraform-exec test for linux amd64 (push) Has been cancelled
* refactor: Move method `ValidWorkspaceName` and related const into arguments package, update references This function is primarily used to validate arguments, but it's used once (in (m *Meta) Workspace) in a different context, so I've left the original function signature in the command package. * feat: Add `workspace new`-related code to arguments package * refactor: Update `workspace new` to use the arguments package when parsing arguments Note that this changes the format of errors returned when arg parsing fails - this is now wrapped in a diagnostic so now starts with `\nError: ` and has an extra trailing newline. * feat: Add `workspace select`-related code to arguments package * refactor: Update `workspace select` to use the arguments package when parsing arguments Note that this changes the format of errors returned when arg parsing fails - this is now wrapped in a diagnostic so now starts with `\nError: ` and has an extra trailing newline.
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
// Copyright IBM Corp. 2014, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package arguments
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
)
|
|
|
|
// WorkspaceDelete represent flags and arguments specific to the `terraform workspace delete` command.
|
|
type WorkspaceDelete struct {
|
|
Workspace
|
|
|
|
// Flags
|
|
Lock bool
|
|
LockTimeout time.Duration
|
|
Force bool
|
|
|
|
// Positional arguments
|
|
Name string
|
|
}
|
|
|
|
// ParseWorkspaceDelete processes CLI arguments, returning a WorkspaceDelete value and errors.
|
|
// If errors are encountered, an WorkspaceDelete value is still returned representing
|
|
// the best effort interpretation of the arguments.
|
|
func ParseWorkspaceDelete(args []string) (*WorkspaceDelete, tfdiags.Diagnostics) {
|
|
var diags tfdiags.Diagnostics
|
|
|
|
var force bool
|
|
var stateLock bool
|
|
var stateLockTimeout time.Duration
|
|
cmdFlags := defaultFlagSet("workspace delete")
|
|
cmdFlags.BoolVar(&force, "force", false, "force removal of a non-empty workspace")
|
|
cmdFlags.BoolVar(&stateLock, "lock", true, "lock state")
|
|
cmdFlags.DurationVar(&stateLockTimeout, "lock-timeout", 0, "lock timeout")
|
|
if err := cmdFlags.Parse(args); err != nil {
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
tfdiags.Error,
|
|
"Failed to parse command-line flags",
|
|
err.Error(),
|
|
))
|
|
}
|
|
|
|
// `workspace delete` takes only one positional argument: workspace name.
|
|
args = cmdFlags.Args()
|
|
var name string
|
|
if len(args) == 0 {
|
|
diags = diags.Append(errors.New("Expected a single argument: NAME.")) // Recreating pre-existing error from command package
|
|
} else {
|
|
|
|
// Obtain and validate name argument
|
|
//
|
|
// We purposefully don't use ValidWorkspaceName here; if a user
|
|
// creates a workspace with an invalid name they should be able to
|
|
// delete it easily.
|
|
name = args[0]
|
|
if name == "" {
|
|
diags = diags.Append(fmt.Errorf("Expected a workspace name as an argument, instead got an empty string: %q\n", args[0]))
|
|
}
|
|
|
|
// Checking for extra arguments here, not with a len != 1 check above, allows the name to be returned
|
|
args = args[1:]
|
|
if len(args) != 0 {
|
|
diags = diags.Append(errors.New("Expected a single argument: NAME."))
|
|
}
|
|
}
|
|
|
|
return &WorkspaceDelete{
|
|
Workspace: Workspace{ViewType: ViewHuman},
|
|
Name: name,
|
|
Lock: stateLock,
|
|
LockTimeout: stateLockTimeout,
|
|
Force: force,
|
|
}, diags
|
|
}
|