Move all implementation of flag.Value in one package (#3725)

Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
This commit is contained in:
Andrei Ciobanu 2026-02-10 16:26:09 +02:00 committed by GitHub
parent 25d652dece
commit da0f45bf69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 173 additions and 224 deletions

View file

@ -12,6 +12,7 @@ import (
"github.com/opentofu/opentofu/internal/backend"
"github.com/opentofu/opentofu/internal/command/arguments"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/command/views"
"github.com/opentofu/opentofu/internal/encryption"
"github.com/opentofu/opentofu/internal/plans/planfile"
@ -301,12 +302,12 @@ func (c *ApplyCommand) GatherVariables(args *arguments.Vars) {
// package directly, removing this shim layer.
varArgs := args.All()
items := make([]rawFlag, len(varArgs))
items := make([]flags.RawFlag, len(varArgs))
for i := range varArgs {
items[i].Name = varArgs[i].Name
items[i].Value = varArgs[i].Value
}
c.Meta.variableArgs = rawFlags{items: &items}
c.Meta.variableArgs = flags.RawFlags{Items: &items}
}
func (c *ApplyCommand) Help() string {

View file

@ -10,6 +10,7 @@ import (
"testing"
"github.com/hashicorp/hcl/v2"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/tfdiags"
"github.com/google/go-cmp/cmp"
@ -712,7 +713,7 @@ func TestParseApply_replace(t *testing.T) {
func TestParseApply_vars(t *testing.T) {
testCases := map[string]struct {
args []string
want []FlagNameValue
want []flags.RawFlag
}{
"no var flags by default": {
args: nil,
@ -720,13 +721,13 @@ func TestParseApply_vars(t *testing.T) {
},
"one var": {
args: []string{"-var", "foo=bar"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
},
},
"one var-file": {
args: []string{"-var-file", "cool.tfvars"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var-file", Value: "cool.tfvars"},
},
},
@ -736,7 +737,7 @@ func TestParseApply_vars(t *testing.T) {
"-var-file", "cool.tfvars",
"-var", "boop=beep",
},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
{Name: "-var-file", Value: "cool.tfvars"},
{Name: "-var", Value: "boop=beep"},

View file

@ -15,6 +15,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/addrs"
"github.com/opentofu/opentofu/internal/plans"
@ -288,11 +289,11 @@ func (o *Operation) Parse() tfdiags.Diagnostics {
// desirable for the arguments package to handle the gathering of variables
// directly, returning a map of variable values.
type Vars struct {
vars *flagNameValueSlice
varFiles *flagNameValueSlice
vars *flags.RawFlags
varFiles *flags.RawFlags
}
func (v *Vars) All() []FlagNameValue {
func (v *Vars) All() []flags.RawFlag {
if v.vars == nil {
return nil
}
@ -329,17 +330,17 @@ func extendedFlagSet(name string, state *State, operation *Operation, vars *Vars
f.BoolVar(&operation.Refresh, "refresh", true, "refresh")
f.BoolVar(&operation.destroyRaw, "destroy", false, "destroy")
f.BoolVar(&operation.refreshOnlyRaw, "refresh-only", false, "refresh-only")
f.Var((*flagStringSlice)(&operation.targetsRaw), "target", "target")
f.Var((*flagStringSlice)(&operation.targetsFilesRaw), "target-file", "target-file")
f.Var((*flagStringSlice)(&operation.excludesRaw), "exclude", "exclude")
f.Var((*flagStringSlice)(&operation.excludesFilesRaw), "exclude-file", "exclude-file")
f.Var((*flagStringSlice)(&operation.forceReplaceRaw), "replace", "replace")
f.Var((*flags.FlagStringSlice)(&operation.targetsRaw), "target", "target")
f.Var((*flags.FlagStringSlice)(&operation.targetsFilesRaw), "target-file", "target-file")
f.Var((*flags.FlagStringSlice)(&operation.excludesRaw), "exclude", "exclude")
f.Var((*flags.FlagStringSlice)(&operation.excludesFilesRaw), "exclude-file", "exclude-file")
f.Var((*flags.FlagStringSlice)(&operation.forceReplaceRaw), "replace", "replace")
}
// Gather all -var and -var-file arguments into one heterogeneous structure
// to preserve the overall order.
if vars != nil {
varsFlags := newFlagNameValueSlice("-var")
varsFlags := flags.NewRawFlags("-var")
varFilesFlags := varsFlags.Alias("-var-file")
vars.vars = &varsFlags
vars.varFiles = &varFilesFlags

View file

@ -1,102 +0,0 @@
// 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 (
"flag"
"fmt"
)
// flagStringSlice is a flag.Value implementation which allows collecting
// multiple instances of a single flag into a slice. This is used for flags
// such as -target=aws_instance.foo and -var x=y.
type flagStringSlice []string
var _ flag.Value = (*flagStringSlice)(nil)
func (v *flagStringSlice) String() string {
return ""
}
func (v *flagStringSlice) Set(raw string) error {
*v = append(*v, raw)
return nil
}
// flagNameValueSlice is a flag.Value implementation that appends raw flag
// names and values to a slice. This is used to collect a sequence of flags
// with possibly different names, preserving the overall order.
//
// FIXME: this is a copy of rawFlags from command/meta_config.go, with the
// eventual aim of replacing it altogether by gathering variables in the
// arguments package.
type flagNameValueSlice struct {
flagName string
items *[]FlagNameValue
}
var _ flag.Value = flagNameValueSlice{}
func newFlagNameValueSlice(flagName string) flagNameValueSlice {
var items []FlagNameValue
return flagNameValueSlice{
flagName: flagName,
items: &items,
}
}
func (f flagNameValueSlice) Empty() bool {
if f.items == nil {
return true
}
return len(*f.items) == 0
}
func (f flagNameValueSlice) AllItems() []FlagNameValue {
if f.items == nil {
return nil
}
return *f.items
}
func (f flagNameValueSlice) Alias(flagName string) flagNameValueSlice {
return flagNameValueSlice{
flagName: flagName,
items: f.items,
}
}
func (f flagNameValueSlice) String() string {
return ""
}
func (f flagNameValueSlice) Set(str string) error {
*f.items = append(*f.items, FlagNameValue{
Name: f.flagName,
Value: str,
})
return nil
}
type FlagNameValue struct {
Name string
Value string
}
func (f FlagNameValue) String() string {
return fmt.Sprintf("%s=%q", f.Name, f.Value)
}
// FlagIsSet returns whether a flag is explicitly set in a set of flags
func FlagIsSet(flags *flag.FlagSet, name string) bool {
isSet := false
flags.Visit(func(f *flag.Flag) {
if f.Name == name {
isSet = true
}
})
return isSet
}

View file

@ -9,6 +9,7 @@ import (
"strings"
"testing"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/tfdiags"
"github.com/google/go-cmp/cmp"
@ -611,7 +612,7 @@ func TestParsePlan_excludeAndTarget(t *testing.T) {
func TestParsePlan_vars(t *testing.T) {
testCases := map[string]struct {
args []string
want []FlagNameValue
want []flags.RawFlag
}{
"no var flags by default": {
args: nil,
@ -619,13 +620,13 @@ func TestParsePlan_vars(t *testing.T) {
},
"one var": {
args: []string{"-var", "foo=bar"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
},
},
"one var-file": {
args: []string{"-var-file", "cool.tfvars"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var-file", Value: "cool.tfvars"},
},
},
@ -635,7 +636,7 @@ func TestParsePlan_vars(t *testing.T) {
"-var-file", "cool.tfvars",
"-var", "boop=beep",
},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
{Name: "-var-file", Value: "cool.tfvars"},
{Name: "-var", Value: "boop=beep"},

View file

@ -12,6 +12,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/hcl/v2"
"github.com/opentofu/opentofu/internal/addrs"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/tfdiags"
)
@ -440,7 +441,7 @@ func TestParseRefresh_excludeAndTarget(t *testing.T) {
func TestParseRefresh_vars(t *testing.T) {
testCases := map[string]struct {
args []string
want []FlagNameValue
want []flags.RawFlag
}{
"no var flags by default": {
args: nil,
@ -448,13 +449,13 @@ func TestParseRefresh_vars(t *testing.T) {
},
"one var": {
args: []string{"-var", "foo=bar"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
},
},
"one var-file": {
args: []string{"-var-file", "cool.tfvars"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var-file", Value: "cool.tfvars"},
},
},
@ -464,7 +465,7 @@ func TestParseRefresh_vars(t *testing.T) {
"-var-file", "cool.tfvars",
"-var", "boop=beep",
},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
{Name: "-var-file", Value: "cool.tfvars"},
{Name: "-var", Value: "boop=beep"},

View file

@ -6,6 +6,7 @@
package arguments
import (
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/configs"
"github.com/opentofu/opentofu/internal/tfdiags"
)
@ -42,7 +43,7 @@ func ParseTest(args []string) (*Test, func(), tfdiags.Diagnostics) {
}
cmdFlags := extendedFlagSet("test", nil, nil, test.Vars)
cmdFlags.Var((*flagStringSlice)(&test.Filter), "filter", "filter")
cmdFlags.Var((*flags.FlagStringSlice)(&test.Filter), "filter", "filter")
cmdFlags.StringVar(&test.TestDirectory, "test-directory", configs.DefaultTestDirectory, "test-directory")
cmdFlags.BoolVar(&test.Verbose, "verbose", false, "verbose")

View file

@ -12,6 +12,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/tfdiags"
)
@ -19,7 +20,7 @@ import (
func TestParseTest_Vars(t *testing.T) {
tcs := map[string]struct {
args []string
want []FlagNameValue
want []flags.RawFlag
}{
"no var flags by default": {
args: nil,
@ -27,13 +28,13 @@ func TestParseTest_Vars(t *testing.T) {
},
"one var": {
args: []string{"-var", "foo=bar"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
},
},
"one var-file": {
args: []string{"-var-file", "cool.tfvars"},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var-file", Value: "cool.tfvars"},
},
},
@ -43,7 +44,7 @@ func TestParseTest_Vars(t *testing.T) {
"-var-file", "cool.tfvars",
"-var", "boop=beep",
},
want: []FlagNameValue{
want: []flags.RawFlag{
{Name: "-var", Value: "foo=bar"},
{Name: "-var-file", Value: "cool.tfvars"},
{Name: "-var", Value: "boop=beep"},

View file

@ -3,9 +3,10 @@
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package command
package flags
import (
"flag"
"fmt"
"strings"
)
@ -34,10 +35,13 @@ func (v *FlagStringKV) Set(raw string) error {
return nil
}
// FlagStringSlice is a flag.Value implementation for parsing targets from the
// command line, e.g. -target=aws_instance.foo -target=aws_vpc.bar
// FlagStringSlice is a flag.Value implementation which allows collecting
// multiple instances of a single flag into a slice. This is used for flags
// such as -target=aws_instance.foo and -var x=y.
type FlagStringSlice []string
var _ flag.Value = (*FlagStringSlice)(nil)
func (v *FlagStringSlice) String() string {
return ""
}

View file

@ -3,7 +3,7 @@
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package command
package flags
import (
"flag"

View file

@ -0,0 +1,21 @@
// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package flags
import (
"flag"
)
// FlagIsSet returns whether a flag is explicitly set in a set of flags
func FlagIsSet(flags *flag.FlagSet, name string) bool {
isSet := false
flags.Visit(func(f *flag.Flag) {
if f.Name == name {
isSet = true
}
})
return isSet
}

View file

@ -0,0 +1,71 @@
// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package flags
import (
"flag"
"fmt"
)
// RawFlags is a flag.Value implementation that appends raw flag
// names and values to a slice. This is used to collect a sequence of flags
// with possibly different names, preserving the overall order.
type RawFlags struct {
Name string
Items *[]RawFlag
}
var _ flag.Value = RawFlags{}
func NewRawFlags(name string) RawFlags {
var items []RawFlag
return RawFlags{
Name: name,
Items: &items,
}
}
func (f RawFlags) Empty() bool {
if f.Items == nil {
return true
}
return len(*f.Items) == 0
}
func (f RawFlags) AllItems() []RawFlag {
if f.Items == nil {
return nil
}
return *f.Items
}
func (f RawFlags) Alias(flagName string) RawFlags {
return RawFlags{
Name: flagName,
Items: f.Items,
}
}
func (f RawFlags) String() string {
return ""
}
func (f RawFlags) Set(str string) error {
*f.Items = append(*f.Items, RawFlag{
Name: f.Name,
Value: str,
})
return nil
}
type RawFlag struct {
Name string
Value string
}
func (f RawFlag) String() string {
return fmt.Sprintf("%s=%q", f.Name, f.Value)
}

View file

@ -14,6 +14,7 @@ import (
"strings"
"github.com/hashicorp/hcl/v2"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/svchost"
"github.com/posener/complete"
"github.com/zclconf/go-cty/cty"
@ -52,8 +53,8 @@ func (c *InitCommand) Run(args []string) int {
var flagFromModule, flagLockfile, testsDirectory string
var flagBackend, flagCloud, flagGet, flagUpgrade bool
var flagPluginPath FlagStringSlice
flagConfigExtra := newRawFlags("-backend-config")
var flagPluginPath flags.FlagStringSlice
flagConfigExtra := flags.NewRawFlags("-backend-config")
args = c.Meta.process(args)
cmdFlags := c.Meta.extendedFlagSet("init")
@ -114,8 +115,8 @@ func (c *InitCommand) Run(args []string) int {
}
}
backendFlagSet := arguments.FlagIsSet(cmdFlags, "backend")
cloudFlagSet := arguments.FlagIsSet(cmdFlags, "cloud")
backendFlagSet := flags.FlagIsSet(cmdFlags, "backend")
cloudFlagSet := flags.FlagIsSet(cmdFlags, "cloud")
switch {
case backendFlagSet && cloudFlagSet:
@ -470,7 +471,7 @@ func (c *InitCommand) getModules(ctx context.Context, path, testsDir string, ear
return true, installAbort, diags
}
func (c *InitCommand) initCloud(ctx context.Context, root *configs.Module, extraConfig rawFlags, enc encryption.Encryption) (be backend.Backend, output bool, diags tfdiags.Diagnostics) {
func (c *InitCommand) initCloud(ctx context.Context, root *configs.Module, extraConfig flags.RawFlags, enc encryption.Encryption) (be backend.Backend, output bool, diags tfdiags.Diagnostics) {
ctx, span := tracing.Tracer().Start(ctx, "Cloud backend init")
_ = ctx // prevent staticcheck from complaining to avoid a maintenance hazard of having the wrong ctx in scope here
defer span.End()
@ -498,7 +499,7 @@ func (c *InitCommand) initCloud(ctx context.Context, root *configs.Module, extra
return back, true, diags
}
func (c *InitCommand) initBackend(ctx context.Context, root *configs.Module, extraConfig rawFlags, enc encryption.Encryption) (be backend.Backend, output bool, diags tfdiags.Diagnostics) {
func (c *InitCommand) initBackend(ctx context.Context, root *configs.Module, extraConfig flags.RawFlags, enc encryption.Encryption) (be backend.Backend, output bool, diags tfdiags.Diagnostics) {
ctx, span := tracing.Tracer().Start(ctx, "Backend init")
_ = ctx // prevent staticcheck from complaining to avoid a maintenance hazard of having the wrong ctx in scope here
defer span.End()
@ -1132,7 +1133,7 @@ func warnOnFailedImplicitProvReference(provider addrs.Provider, qualifs *getprov
//
// If the returned diagnostics contains errors then the returned body may be
// incomplete or invalid.
func (c *InitCommand) backendConfigOverrideBody(flags rawFlags, schema *configschema.Block) (hcl.Body, tfdiags.Diagnostics) {
func (c *InitCommand) backendConfigOverrideBody(flags flags.RawFlags, schema *configschema.Block) (hcl.Body, tfdiags.Diagnostics) {
items := flags.AllItems()
if len(items) == 0 {
return nil, nil

View file

@ -22,6 +22,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-version"
"github.com/mitchellh/cli"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/command/workdir"
"github.com/zclconf/go-cty/cty"
@ -460,7 +461,7 @@ func TestInit_backendConfigFile(t *testing.T) {
},
},
}
flagConfigExtra := newRawFlags("-backend-config")
flagConfigExtra := flags.NewRawFlags("-backend-config")
_ = flagConfigExtra.Set("input.config")
_, diags := c.backendConfigOverrideBody(flagConfigExtra, schema)
if len(diags) != 0 {

View file

@ -23,6 +23,7 @@ import (
"github.com/hashicorp/go-retryablehttp"
"github.com/mitchellh/cli"
"github.com/mitchellh/colorstring"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/svchost/disco"
"github.com/opentofu/opentofu/internal/addrs"
@ -226,7 +227,7 @@ type Meta struct {
backendState *legacy.BackendState
// Variables for the context (private)
variableArgs rawFlags
variableArgs flags.RawFlags
input bool
// Targets for this context (private)
@ -613,8 +614,8 @@ func (m *Meta) ignoreRemoteVersionFlagSet(n string) *flag.FlagSet {
}
func (m *Meta) varFlagSet(f *flag.FlagSet) {
if m.variableArgs.items == nil {
m.variableArgs = newRawFlags("-var")
if m.variableArgs.Items == nil {
m.variableArgs = flags.NewRawFlags("-var")
}
varValues := m.variableArgs.Alias("-var")
varFiles := m.variableArgs.Alias("-var-file")
@ -628,8 +629,8 @@ func (m *Meta) extendedFlagSet(n string) *flag.FlagSet {
f := m.defaultFlagSet(n)
f.BoolVar(&m.input, "input", true, "input")
f.Var((*FlagStringSlice)(&m.targetFlags), "target", "resource to target")
f.Var((*FlagStringSlice)(&m.excludeFlags), "exclude", "resource to exclude")
f.Var((*flags.FlagStringSlice)(&m.targetFlags), "target", "resource to target")
f.Var((*flags.FlagStringSlice)(&m.excludeFlags), "exclude", "resource to exclude")
f.BoolVar(&m.compactWarnings, "compact-warnings", false, "use compact warnings")
f.BoolVar(&m.consolidateWarnings, "consolidate-warnings", true, "consolidate warnings")
f.BoolVar(&m.consolidateErrors, "consolidate-errors", false, "consolidate errors")

View file

@ -505,60 +505,3 @@ func configValueFromCLI(synthFilename, rawValue string, wantType cty.Type) (cty.
return val, diags
}
}
// rawFlags is a flag.Value implementation that just appends raw flag
// names and values to a slice.
type rawFlags struct {
flagName string
items *[]rawFlag
}
func newRawFlags(flagName string) rawFlags {
var items []rawFlag
return rawFlags{
flagName: flagName,
items: &items,
}
}
func (f rawFlags) Empty() bool {
if f.items == nil {
return true
}
return len(*f.items) == 0
}
func (f rawFlags) AllItems() []rawFlag {
if f.items == nil {
return nil
}
return *f.items
}
func (f rawFlags) Alias(flagName string) rawFlags {
return rawFlags{
flagName: flagName,
items: f.items,
}
}
func (f rawFlags) String() string {
return ""
}
func (f rawFlags) Set(str string) error {
*f.items = append(*f.items, rawFlag{
Name: f.flagName,
Value: str,
})
return nil
}
type rawFlag struct {
Name string
Value string
}
func (f rawFlag) String() string {
return fmt.Sprintf("%s=%q", f.Name, f.Value)
}

View file

@ -11,6 +11,7 @@ import (
"strings"
"github.com/opentofu/opentofu/internal/command/arguments"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/command/views"
"github.com/opentofu/opentofu/internal/encryption"
"github.com/opentofu/opentofu/internal/states"
@ -121,12 +122,12 @@ func (c *OutputCommand) GatherVariables(args *arguments.Vars) {
// package directly, removing this shim layer.
varArgs := args.All()
items := make([]rawFlag, len(varArgs))
items := make([]flags.RawFlag, len(varArgs))
for i := range varArgs {
items[i].Name = varArgs[i].Name
items[i].Value = varArgs[i].Value
}
c.Meta.variableArgs = rawFlags{items: &items}
c.Meta.variableArgs = flags.RawFlags{Items: &items}
}
func (c *OutputCommand) Help() string {

View file

@ -12,6 +12,7 @@ import (
"github.com/opentofu/opentofu/internal/backend"
"github.com/opentofu/opentofu/internal/command/arguments"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/command/views"
"github.com/opentofu/opentofu/internal/encryption"
"github.com/opentofu/opentofu/internal/tfdiags"
@ -195,12 +196,12 @@ func (c *PlanCommand) GatherVariables(args *arguments.Vars) {
// package directly, removing this shim layer.
varArgs := args.All()
items := make([]rawFlag, len(varArgs))
items := make([]flags.RawFlag, len(varArgs))
for i := range varArgs {
items[i].Name = varArgs[i].Name
items[i].Value = varArgs[i].Value
}
c.Meta.variableArgs = rawFlags{items: &items}
c.Meta.variableArgs = flags.RawFlags{Items: &items}
}
func (c *PlanCommand) Help() string {

View file

@ -11,6 +11,7 @@ import (
"os"
"github.com/opentofu/opentofu/internal/addrs"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/depsfile"
"github.com/opentofu/opentofu/internal/getproviders"
"github.com/opentofu/opentofu/internal/providercache"
@ -48,7 +49,7 @@ func (c *ProvidersLockCommand) Run(args []string) int {
args = c.Meta.process(args)
cmdFlags := c.Meta.defaultFlagSet("providers lock")
c.Meta.varFlagSet(cmdFlags)
var optPlatforms FlagStringSlice
var optPlatforms flags.FlagStringSlice
var fsMirrorDir string
var netMirrorURL string
cmdFlags.Var(&optPlatforms, "platform", "target platform")

View file

@ -14,6 +14,7 @@ import (
"github.com/apparentlymart/go-versions/versions"
"github.com/hashicorp/go-getter"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/getproviders"
"github.com/opentofu/opentofu/internal/httpclient"
@ -36,7 +37,7 @@ func (c *ProvidersMirrorCommand) Run(args []string) int {
args = c.Meta.process(args)
cmdFlags := c.Meta.defaultFlagSet("providers mirror")
c.Meta.varFlagSet(cmdFlags)
var optPlatforms FlagStringSlice
var optPlatforms flags.FlagStringSlice
cmdFlags.Var(&optPlatforms, "platform", "target platform")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {

View file

@ -12,6 +12,7 @@ import (
"github.com/opentofu/opentofu/internal/backend"
"github.com/opentofu/opentofu/internal/command/arguments"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/command/views"
"github.com/opentofu/opentofu/internal/encryption"
"github.com/opentofu/opentofu/internal/tfdiags"
@ -176,12 +177,12 @@ func (c *RefreshCommand) GatherVariables(args *arguments.Vars) {
// package directly, removing this shim layer.
varArgs := args.All()
items := make([]rawFlag, len(varArgs))
items := make([]flags.RawFlag, len(varArgs))
for i := range varArgs {
items[i].Name = varArgs[i].Name
items[i].Value = varArgs[i].Value
}
c.Meta.variableArgs = rawFlags{items: &items}
c.Meta.variableArgs = flags.RawFlags{Items: &items}
}
func (c *RefreshCommand) Help() string {

View file

@ -16,6 +16,7 @@ import (
"github.com/opentofu/opentofu/internal/cloud"
"github.com/opentofu/opentofu/internal/cloud/cloudplan"
"github.com/opentofu/opentofu/internal/command/arguments"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/command/views"
"github.com/opentofu/opentofu/internal/configs"
"github.com/opentofu/opentofu/internal/encryption"
@ -176,12 +177,12 @@ func (c *ShowCommand) GatherVariables(args *arguments.Vars) {
// package directly, removing this shim layer.
varArgs := args.All()
items := make([]rawFlag, len(varArgs))
items := make([]flags.RawFlag, len(varArgs))
for i := range varArgs {
items[i].Name = varArgs[i].Name
items[i].Value = varArgs[i].Value
}
c.Meta.variableArgs = rawFlags{items: &items}
c.Meta.variableArgs = flags.RawFlags{Items: &items}
}
type showRenderFunc func(view views.Show) int

View file

@ -16,6 +16,7 @@ import (
"strings"
"time"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/lang"
"github.com/hashicorp/hcl/v2"
@ -141,14 +142,8 @@ func (c *TestCommand) Run(rawArgs []string) int {
// Users can also specify variables via the command line, so we'll parse
// all that here.
var items []rawFlag
for _, variable := range args.Vars.All() {
items = append(items, rawFlag{
Name: variable.Name,
Value: variable.Value,
})
}
c.variableArgs = rawFlags{items: &items}
items := args.Vars.All()
c.variableArgs = flags.RawFlags{Items: &items}
variables, variableDiags := c.collectVariableValuesWithTests(args.TestDirectory)
diags = diags.Append(variableDiags)

View file

@ -13,6 +13,7 @@ import (
"github.com/opentofu/opentofu/internal/addrs"
"github.com/opentofu/opentofu/internal/command/arguments"
"github.com/opentofu/opentofu/internal/command/flags"
"github.com/opentofu/opentofu/internal/command/views"
"github.com/opentofu/opentofu/internal/configs"
"github.com/opentofu/opentofu/internal/tfdiags"
@ -84,12 +85,12 @@ func (c *ValidateCommand) GatherVariables(args *arguments.Vars) {
// package directly, removing this shim layer.
varArgs := args.All()
items := make([]rawFlag, len(varArgs))
items := make([]flags.RawFlag, len(varArgs))
for i := range varArgs {
items[i].Name = varArgs[i].Name
items[i].Value = varArgs[i].Value
}
c.Meta.variableArgs = rawFlags{items: &items}
c.Meta.variableArgs = flags.RawFlags{Items: &items}
}
func (c *ValidateCommand) validate(ctx context.Context, dir, testDir string, noTests bool) tfdiags.Diagnostics {