| 24 | } |
| 25 | |
| 26 | func (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 | |
| 76 | func (c *OutputCommand) Outputs(ctx context.Context, statePath string, enc encryption.Encryption) (map[string]*states.OutputValue, tfdiags.Diagnostics) { |
| 77 | var diags tfdiags.Diagnostics |