Files
opentf/internal/command/arguments/workspace.go
2026-03-03 12:44:56 +02:00

44 lines
1.1 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package arguments
import (
"github.com/opentofu/opentofu/internal/tfdiags"
)
type Workspace struct {
// ViewOptions contains the options that allows the user to configure different types of outputs
// from the current command.
ViewOptions ViewOptions
}
func ParseWorkspace(args []string) (*Workspace, func(), tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
ret := &Workspace{}
cmdFlags := defaultFlagSet("workspace")
if err := cmdFlags.Parse(args); err != nil {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to parse command-line flags",
err.Error(),
))
}
if len(cmdFlags.Args()) > 0 {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Unexpected argument",
"Too many command line arguments. Did you mean to use -chdir?",
))
}
// we only parse but do not register the views flags since this command does not need it
closer, moreDiags := ret.ViewOptions.Parse()
diags = diags.Append(moreDiags)
return ret, closer, diags
}