mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
ffe056bacb
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package arguments
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
)
|
|
|
|
// Refresh represents the command-line arguments for the apply command.
|
|
type Refresh struct {
|
|
// State, Operation, and Vars are the common extended flags
|
|
State *State
|
|
Operation *Operation
|
|
Vars *Vars
|
|
|
|
// InputEnabled is used to disable interactive input for unspecified
|
|
// variable and backend config values. Default is true.
|
|
InputEnabled bool
|
|
|
|
// ViewType specifies which output format to use
|
|
ViewType ViewType
|
|
}
|
|
|
|
// ParseRefresh processes CLI arguments, returning a Refresh value and errors.
|
|
// If errors are encountered, a Refresh value is still returned representing
|
|
// the best effort interpretation of the arguments.
|
|
func ParseRefresh(args []string) (*Refresh, tfdiags.Diagnostics) {
|
|
var diags tfdiags.Diagnostics
|
|
refresh := &Refresh{
|
|
State: &State{},
|
|
Operation: &Operation{},
|
|
Vars: &Vars{},
|
|
}
|
|
|
|
cmdFlags := extendedFlagSet("refresh", refresh.State, refresh.Operation, refresh.Vars)
|
|
cmdFlags.BoolVar(&refresh.InputEnabled, "input", true, "input")
|
|
|
|
var json bool
|
|
cmdFlags.BoolVar(&json, "json", false, "json")
|
|
|
|
if err := cmdFlags.Parse(args); err != nil {
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
tfdiags.Error,
|
|
"Failed to parse command-line flags",
|
|
err.Error(),
|
|
))
|
|
}
|
|
|
|
args = cmdFlags.Args()
|
|
if len(args) > 0 {
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
tfdiags.Error,
|
|
"Too many command line arguments",
|
|
"Expected at most one positional argument.",
|
|
))
|
|
}
|
|
|
|
diags = diags.Append(refresh.Operation.Parse())
|
|
|
|
// JSON view currently does not support input, so we disable it here
|
|
if json {
|
|
refresh.InputEnabled = false
|
|
}
|
|
|
|
switch {
|
|
case json:
|
|
refresh.ViewType = ViewJSON
|
|
default:
|
|
refresh.ViewType = ViewHuman
|
|
}
|
|
|
|
return refresh, diags
|
|
}
|