-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathsummary.go
More file actions
108 lines (93 loc) · 2.8 KB
/
summary.go
File metadata and controls
108 lines (93 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package bundle
import (
"context"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config/mutator"
"github.com/databricks/cli/bundle/render"
"github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/cli/libs/logdiag"
"github.com/spf13/cobra"
)
func newSummaryCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "summary",
Short: "Summarize resources deployed by this bundle",
Long: `Summarize resources deployed by this bundle with their workspace URLs.
Useful after deployment to see what was created and where to find it.`,
Args: root.NoArgs,
}
var forcePull bool
var includeLocations bool
var shouldShowFullConfig bool
cmd.Flags().BoolVar(&forcePull, "force-pull", false, "Skip local cache and load the state from the remote workspace")
cmd.Flags().BoolVar(&includeLocations, "include-locations", false, "Include location information in the output")
cmd.Flags().MarkHidden("include-locations")
cmd.Flags().BoolVar(&shouldShowFullConfig, "show-full-config", false, "Load and output the full bundle config")
cmd.Flags().MarkHidden("show-full-config")
cmd.RunE = func(cmd *cobra.Command, args []string) error {
var err error
if shouldShowFullConfig {
ctx := logdiag.InitContext(cmd.Context())
cmd.SetContext(ctx)
logdiag.SetSeverity(ctx, diag.Warning)
err = showFullConfig(ctx, cmd, includeLocations)
if err != nil {
return err
}
} else {
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{
ReadState: true,
IncludeLocations: includeLocations,
InitIDs: true,
})
if err != nil {
return err
}
err = showSummary(cmd, b)
if err != nil {
return err
}
}
if logdiag.HasError(cmd.Context()) {
return root.ErrAlreadyPrinted
}
return nil
}
return cmd
}
func showFullConfig(ctx context.Context, cmd *cobra.Command, includeLocations bool) error {
// call `MustLoad` directly instead of `MustConfigureBundle` because the latter does
// validation that we're not interested in here
b := bundle.MustLoad(ctx)
if b == nil || logdiag.HasError(ctx) {
return nil
}
mutator.DefaultMutators(ctx, b)
if logdiag.HasError(ctx) {
return nil
}
if includeLocations {
// Include location information in the output
bundle.ApplyContext(ctx, b, mutator.PopulateLocations())
if logdiag.HasError(ctx) {
return nil
}
}
err := renderJsonOutput(cmd, b)
if err != nil {
return err
}
return nil
}
func showSummary(cmd *cobra.Command, b *bundle.Bundle) error {
if root.OutputType(cmd) == flags.OutputText {
return render.RenderSummary(cmd.Context(), cmd.OutOrStdout(), b)
}
if root.OutputType(cmd) == flags.OutputJSON {
return renderJsonOutput(cmd, b)
}
return nil
}