2023-05-02 11:33:06 -04:00
|
|
|
// Copyright IBM Corp. 2014, 2026
|
2023-08-10 18:43:27 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-05-02 11:33:06 -04:00
|
|
|
|
2021-02-22 11:38:39 -05:00
|
|
|
package arguments
|
|
|
|
|
|
|
|
|
|
import (
|
2021-05-17 13:11:06 -04:00
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
2021-02-22 11:38:39 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
|
|
2021-02-23 10:16:09 -05:00
|
|
|
var json bool
|
|
|
|
|
cmdFlags.BoolVar(&json, "json", false, "json")
|
|
|
|
|
|
2021-02-22 11:38:39 -05:00
|
|
|
if err := cmdFlags.Parse(args); err != nil {
|
|
|
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
|
|
|
tfdiags.Error,
|
|
|
|
|
"Failed to parse command-line flags",
|
|
|
|
|
err.Error(),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-05 04:55:37 -04:00
|
|
|
if refresh.State.StatePath != "" {
|
|
|
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
|
|
|
tfdiags.Warning,
|
|
|
|
|
"Deprecated flag: -state",
|
2025-02-28 13:02:43 -05:00
|
|
|
`Use the "path" attribute within the "local" backend to specify a file for state storage`,
|
2024-09-05 04:55:37 -04:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 11:38:39 -05:00
|
|
|
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())
|
|
|
|
|
|
2025-08-28 08:11:52 -04:00
|
|
|
if len(refresh.Operation.ActionTargets) > 0 {
|
|
|
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
|
|
|
tfdiags.Error,
|
|
|
|
|
"Invalid arguments",
|
|
|
|
|
"Actions cannot be specified during refresh operations."))
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-23 10:16:09 -05:00
|
|
|
// JSON view currently does not support input, so we disable it here
|
|
|
|
|
if json {
|
|
|
|
|
refresh.InputEnabled = false
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 11:38:39 -05:00
|
|
|
switch {
|
2021-02-23 10:16:09 -05:00
|
|
|
case json:
|
|
|
|
|
refresh.ViewType = ViewJSON
|
2021-02-22 11:38:39 -05:00
|
|
|
default:
|
|
|
|
|
refresh.ViewType = ViewHuman
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return refresh, diags
|
|
|
|
|
}
|