mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-16 07:01:54 -04:00
In order to be able to get rid of the state related configurations from Meta, we want to be able to register those flags from one single location. We want also to be able to register these in a more granular way, since some commands require only the locking specific flags, while other commands use also the state path or backup path. Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
55 lines
1.5 KiB
Go
55 lines
1.5 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"
|
|
)
|
|
|
|
// StatePull represents the command-line arguments for the 'state pull' command.
|
|
type StatePull struct {
|
|
// ViewOptions specifies which view options to use
|
|
ViewOptions ViewOptions
|
|
|
|
// Vars are the common extended flags
|
|
Vars *Vars
|
|
}
|
|
|
|
// ParseStatePull processes CLI arguments, returning a StatePull value, a closer function, and errors.
|
|
// If errors are encountered, a StatePull value is still returned representing
|
|
// the best effort interpretation of the arguments.
|
|
func ParseStatePull(args []string) (*StatePull, func(), tfdiags.Diagnostics) {
|
|
var diags tfdiags.Diagnostics
|
|
|
|
ret := &StatePull{
|
|
Vars: &Vars{},
|
|
}
|
|
cmdFlags := extendedFlagSet("state pull", nil, ret.Vars)
|
|
|
|
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 because it already
|
|
// prints the state in json format
|
|
closer, moreDiags := ret.ViewOptions.Parse()
|
|
diags = diags.Append(moreDiags)
|
|
|
|
return ret, closer, diags
|
|
}
|