MCPcopy
hub / github.com/opentofu/opentofu / Run

Method Run

internal/command/output.go:26–74  ·  view source on GitHub ↗
(rawArgs []string)

Source from the content-addressed store, hash-verified

24}
25
26func (c *OutputCommand) Run(rawArgs []string) int {
27 ctx := c.CommandContext()
28 // Parse and apply global view arguments
29 common, rawArgs := arguments.ParseView(rawArgs)
30 c.View.Configure(common)
31
32 // Parse and validate flags
33 args, closer, diags := arguments.ParseOutput(rawArgs)
34 defer closer()
35 if diags.HasErrors() {
36 c.View.Diagnostics(diags)
37 c.View.HelpPrompt("output")
38 return 1
39 }
40
41 c.View.SetShowSensitive(args.ShowSensitive)
42
43 view := views.NewOutput(args.ViewOptions, c.View)
44
45 // Inject variables from args into meta for static evaluation
46 c.Meta.variableArgs = args.Vars.All()
47
48 // Load the encryption configuration
49 enc, encDiags := c.Encryption(ctx)
50 diags = diags.Append(encDiags)
51 if encDiags.HasErrors() {
52 c.View.Diagnostics(diags)
53 return 1
54 }
55
56 // Fetch data from state
57 outputs, diags := c.Outputs(ctx, args.StatePath, enc)
58 if diags.HasErrors() {
59 view.Diagnostics(diags)
60 return 1
61 }
62
63 // Render the view
64 viewDiags := view.Output(args.Name, outputs)
65 diags = diags.Append(viewDiags)
66
67 view.Diagnostics(diags)
68
69 if diags.HasErrors() {
70 return 1
71 }
72
73 return 0
74}
75
76func (c *OutputCommand) Outputs(ctx context.Context, statePath string, enc encryption.Encryption) (map[string]*states.OutputValue, tfdiags.Diagnostics) {
77 var diags tfdiags.Diagnostics

Callers 12

TestOutputFunction · 0.95
TestOutput_jsonFunction · 0.95
TestOutput_emptyOutputsFunction · 0.95
TestOutput_badVarFunction · 0.95
TestOutput_blankFunction · 0.95
TestOutput_manyArgsFunction · 0.95
TestOutput_noArgsFunction · 0.95
TestOutput_noStateFunction · 0.95
TestOutput_noVarsFunction · 0.95
TestOutput_stateDefaultFunction · 0.95

Calls 15

OutputsMethod · 0.95
DiagnosticsMethod · 0.95
OutputMethod · 0.95
ParseViewFunction · 0.92
ParseOutputFunction · 0.92
NewOutputFunction · 0.92
CommandContextMethod · 0.80
HasErrorsMethod · 0.80
SetShowSensitiveMethod · 0.80
EncryptionMethod · 0.80
ConfigureMethod · 0.65
DiagnosticsMethod · 0.65

Tested by 12

TestOutputFunction · 0.76
TestOutput_jsonFunction · 0.76
TestOutput_emptyOutputsFunction · 0.76
TestOutput_badVarFunction · 0.76
TestOutput_blankFunction · 0.76
TestOutput_manyArgsFunction · 0.76
TestOutput_noArgsFunction · 0.76
TestOutput_noStateFunction · 0.76
TestOutput_noVarsFunction · 0.76
TestOutput_stateDefaultFunction · 0.76