Skip to content

Commit 22779c0

Browse files
authored
Add show-full-config flag to bundle summary (#3583)
## Changes Add a `--show-full-config` flag to `bundle summary` to load all config files from `include` and output the config as JSON ## Why To load the whole config for DABs in the workspace ## Tests add acceptance test
1 parent c5dd3dd commit 22779c0

File tree

10 files changed

+135
-13
lines changed

10 files changed

+135
-13
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include:
2+
- targets/*.yml
3+
4+
variables:
5+
mode:
6+
default: development
7+
default:
8+
default: false
9+
10+
targets:
11+
also_default:
12+
mode: development
13+
default: true
14+
workspace:
15+
host: https://example.com

acceptance/bundle/summary/show-full-config/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
>>> [CLI] bundle summary --show-full-config
3+
{
4+
"bundle": {
5+
"name": "test-bundle"
6+
},
7+
"include": [
8+
"targets/default.yml",
9+
"targets/not_default.yml",
10+
"targets/variable_default.yml",
11+
"targets/variable_mode.yml"
12+
],
13+
"targets": {
14+
"also_default": {
15+
"default": true,
16+
"mode": "development",
17+
"workspace": {
18+
"host": "https://example.com"
19+
}
20+
},
21+
"default": {
22+
"default": true,
23+
"mode": "development"
24+
},
25+
"not_default": {
26+
"mode": "production"
27+
},
28+
"variable_default": {
29+
"default": "${var.default}"
30+
},
31+
"variable_mode": {
32+
"mode": "${var.mode}"
33+
}
34+
},
35+
"variables": {
36+
"default": {
37+
"default": false
38+
},
39+
"mode": {
40+
"default": "development"
41+
}
42+
}
43+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI bundle summary --show-full-config
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
targets:
2+
default:
3+
mode: development
4+
default: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
targets:
2+
not_default:
3+
mode: production
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
targets:
2+
variable_default:
3+
default: ${var.default}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
targets:
2+
variable_mode:
3+
mode: ${var.mode}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[Repls]]
2+
Old = '\\\\'
3+
New = '/'

cmd/bundle/summary.go

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bundle
22

33
import (
4+
"context"
45
"errors"
56
"os"
67
"path/filepath"
@@ -30,30 +31,28 @@ Useful after deployment to see what was created and where to find it.`,
3031

3132
var forcePull bool
3233
var includeLocations bool
34+
var shouldShowFullConfig bool
3335
cmd.Flags().BoolVar(&forcePull, "force-pull", false, "Skip local cache and load the state from the remote workspace")
3436
cmd.Flags().BoolVar(&includeLocations, "include-locations", false, "Include location information in the output")
3537
cmd.Flags().MarkHidden("include-locations")
38+
cmd.Flags().BoolVar(&shouldShowFullConfig, "show-full-config", false, "Load and output the full bundle config")
39+
cmd.Flags().MarkHidden("show-full-config")
3640

3741
cmd.RunE = func(cmd *cobra.Command, args []string) error {
3842
var err error
3943
ctx := logdiag.InitContext(cmd.Context())
4044
cmd.SetContext(ctx)
4145
logdiag.SetSeverity(ctx, diag.Warning)
4246

43-
b := prepareBundleForSummary(cmd, forcePull, includeLocations)
44-
45-
if b != nil {
46-
if root.OutputType(cmd) == flags.OutputText {
47-
err = render.RenderSummary(ctx, cmd.OutOrStdout(), b)
48-
if err != nil {
49-
return err
50-
}
47+
if shouldShowFullConfig {
48+
err = showFullConfig(ctx, cmd)
49+
if err != nil {
50+
return err
5151
}
52-
if root.OutputType(cmd) == flags.OutputJSON {
53-
err = renderJsonOutput(cmd, b)
54-
if err != nil {
55-
return err
56-
}
52+
} else {
53+
err = showSummary(ctx, cmd, forcePull, includeLocations)
54+
if err != nil {
55+
return err
5756
}
5857
}
5958

@@ -67,6 +66,49 @@ Useful after deployment to see what was created and where to find it.`,
6766
return cmd
6867
}
6968

69+
func showFullConfig(ctx context.Context, cmd *cobra.Command) error {
70+
// call `MustLoad` directly instead of `MustConfigureBundle` because the latter does
71+
// validation that we're not interested in here
72+
b := bundle.MustLoad(ctx)
73+
if b == nil || logdiag.HasError(ctx) {
74+
return nil
75+
}
76+
77+
mutator.DefaultMutators(ctx, b)
78+
if logdiag.HasError(ctx) {
79+
return nil
80+
}
81+
82+
err := renderJsonOutput(cmd, b)
83+
if err != nil {
84+
return err
85+
}
86+
87+
return nil
88+
}
89+
90+
func showSummary(ctx context.Context, cmd *cobra.Command, forcePull, includeLocations bool) error {
91+
var err error
92+
b := prepareBundleForSummary(cmd, forcePull, includeLocations)
93+
94+
if b != nil {
95+
if root.OutputType(cmd) == flags.OutputText {
96+
err = render.RenderSummary(ctx, cmd.OutOrStdout(), b)
97+
if err != nil {
98+
return err
99+
}
100+
}
101+
if root.OutputType(cmd) == flags.OutputJSON {
102+
err = renderJsonOutput(cmd, b)
103+
if err != nil {
104+
return err
105+
}
106+
}
107+
}
108+
109+
return nil
110+
}
111+
70112
func prepareBundleForSummary(cmd *cobra.Command, forcePull, includeLocations bool) *bundle.Bundle {
71113
b := utils.ConfigureBundleWithVariables(cmd)
72114
ctx := cmd.Context()

0 commit comments

Comments
 (0)