@@ -3,7 +3,6 @@ package bundle
33import (
44 "encoding/json"
55 "errors"
6- "fmt"
76
87 "github.com/databricks/cli/bundle"
98 "github.com/databricks/cli/bundle/config/mutator"
@@ -12,7 +11,6 @@ import (
1211 "github.com/databricks/cli/bundle/render"
1312 "github.com/databricks/cli/cmd/bundle/utils"
1413 "github.com/databricks/cli/cmd/root"
15- "github.com/databricks/cli/libs/diag"
1614 "github.com/databricks/cli/libs/flags"
1715 "github.com/spf13/cobra"
1816)
@@ -67,60 +65,27 @@ func newValidateCommand() *cobra.Command {
6765 diags = diags .Extend (bundle .Apply (ctx , b , mutator .PopulateLocations ()))
6866 }
6967
70- return renderBundle (cmd , b , diags , false )
71- }
72-
73- return cmd
74- }
75-
76- // This function is used to render results both for "bundle validate" and "bundle summary".
77- // In JSON mode, there is no difference in rendering between these two (but there is a difference in how we prepare the bundle).
78- // In non-JSON mode both "bundle validate" and "bundle summary" will print diagnostics to stderr but "bundle validate"
79- // will also print "summary" message via RenderSummaryTable option.
80- func renderBundle (cmd * cobra.Command , b * bundle.Bundle , diags diag.Diagnostics , withBundleSummary bool ) error {
81- ctx := cmd .Context ()
82- switch root .OutputType (cmd ) {
83- case flags .OutputText :
84- // Confusingly RenderSummaryTable relates to "Validation OK" and related messages, it has nothing
85- // to do with "bundle summary" command and we don't want to show it in bundle summary command.
86- renderOpts := render.RenderOptions {RenderSummaryTable : ! withBundleSummary }
87- err1 := render .RenderDiagnostics (cmd .OutOrStdout (), b , diags , renderOpts )
88- if b != nil && withBundleSummary {
89- // Now RenderSummary actually related to "bundle summary"
90- err2 := render .RenderSummary (ctx , cmd .OutOrStdout (), b )
91- if err2 != nil {
92- return err2
68+ if root .OutputType (cmd ) == flags .OutputText {
69+ err := render .RenderDiagnostics (cmd .OutOrStdout (), b , diags , render.RenderOptions {RenderSummaryTable : true })
70+ if err != nil {
71+ return err
9372 }
9473 }
95-
96- if err1 != nil {
97- return err1
98- }
99-
100- if diags .HasError () {
101- return root .ErrAlreadyPrinted
102- }
103-
104- return nil
105- case flags .OutputJSON :
106- renderOpts := render.RenderOptions {RenderSummaryTable : false }
107- err1 := render .RenderDiagnostics (cmd .ErrOrStderr (), b , diags , renderOpts )
108- err2 := renderJsonOutput (cmd , b )
109-
110- if err2 != nil {
111- return err2
112- }
113-
114- if err1 != nil {
115- return err1
74+ if root .OutputType (cmd ) == flags .OutputJSON {
75+ err := render .RenderDiagnostics (cmd .ErrOrStderr (), b , diags , render.RenderOptions {RenderSummaryTable : false })
76+ if err != nil {
77+ return err
78+ }
79+ err = renderJsonOutput (cmd , b )
80+ if err != nil {
81+ return err
82+ }
11683 }
117-
11884 if diags .HasError () {
11985 return root .ErrAlreadyPrinted
12086 }
121-
12287 return nil
123- default :
124- return fmt .Errorf ("unknown output type %s" , root .OutputType (cmd ))
12588 }
89+
90+ return cmd
12691}
0 commit comments