github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/arguments/refresh.go (about) 1 package arguments 2 3 import ( 4 "github.com/hashicorp/terraform/internal/tfdiags" 5 ) 6 7 // Refresh represents the command-line arguments for the apply command. 8 type Refresh struct { 9 // State, Operation, and Vars are the common extended flags 10 State *State 11 Operation *Operation 12 Vars *Vars 13 14 // InputEnabled is used to disable interactive input for unspecified 15 // variable and backend config values. Default is true. 16 InputEnabled bool 17 18 // ViewType specifies which output format to use 19 ViewType ViewType 20 } 21 22 // ParseRefresh processes CLI arguments, returning a Refresh value and errors. 23 // If errors are encountered, a Refresh value is still returned representing 24 // the best effort interpretation of the arguments. 25 func ParseRefresh(args []string) (*Refresh, tfdiags.Diagnostics) { 26 var diags tfdiags.Diagnostics 27 refresh := &Refresh{ 28 State: &State{}, 29 Operation: &Operation{}, 30 Vars: &Vars{}, 31 } 32 33 cmdFlags := extendedFlagSet("refresh", refresh.State, refresh.Operation, refresh.Vars) 34 cmdFlags.BoolVar(&refresh.InputEnabled, "input", true, "input") 35 36 var json bool 37 cmdFlags.BoolVar(&json, "json", false, "json") 38 39 if err := cmdFlags.Parse(args); err != nil { 40 diags = diags.Append(tfdiags.Sourceless( 41 tfdiags.Error, 42 "Failed to parse command-line flags", 43 err.Error(), 44 )) 45 } 46 47 args = cmdFlags.Args() 48 if len(args) > 0 { 49 diags = diags.Append(tfdiags.Sourceless( 50 tfdiags.Error, 51 "Too many command line arguments", 52 "Expected at most one positional argument.", 53 )) 54 } 55 56 diags = diags.Append(refresh.Operation.Parse()) 57 58 // JSON view currently does not support input, so we disable it here 59 if json { 60 refresh.InputEnabled = false 61 } 62 63 switch { 64 case json: 65 refresh.ViewType = ViewJSON 66 default: 67 refresh.ViewType = ViewHuman 68 } 69 70 return refresh, diags 71 }