Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 214
Simplify cmd/bundle/{summary,validate}.go#3182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,6 @@ package bundle | ||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/config/mutator" | ||
| @@ -12,7 +11,6 @@ import ( | ||
| "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/spf13/cobra" | ||
| ) | ||
| @@ -67,60 +65,27 @@ func newValidateCommand() *cobra.Command { | ||
| diags = diags.Extend(bundle.Apply(ctx, b, mutator.PopulateLocations())) | ||
| } | ||
| return renderBundle(cmd, b, diags, false) | ||
| } | ||
| return cmd | ||
| } | ||
| // This function is used to render results both for "bundle validate" and "bundle summary". | ||
| // In JSON mode, there is no difference in rendering between these two (but there is a difference in how we prepare the bundle). | ||
| // In non-JSON mode both "bundle validate" and "bundle summary" will print diagnostics to stderr but "bundle validate" | ||
| // will also print "summary" message via RenderSummaryTable option. | ||
| func renderBundle(cmd *cobra.Command, b *bundle.Bundle, diags diag.Diagnostics, withBundleSummary bool) error { | ||
| ctx := cmd.Context() | ||
| switch root.OutputType(cmd) { | ||
| case flags.OutputText: | ||
| // Confusingly RenderSummaryTable relates to "Validation OK" and related messages, it has nothing | ||
| // to do with "bundle summary" command and we don't want to show it in bundle summary command. | ||
| renderOpts := render.RenderOptions{RenderSummaryTable: !withBundleSummary} | ||
| err1 := render.RenderDiagnostics(cmd.OutOrStdout(), b, diags, renderOpts) | ||
| if b != nil && withBundleSummary { | ||
| // Now RenderSummary actually related to "bundle summary" | ||
| err2 := render.RenderSummary(ctx, cmd.OutOrStdout(), b) | ||
| if err2 != nil { | ||
| return err2 | ||
| if root.OutputType(cmd) == flags.OutputText { | ||
| err := render.RenderDiagnostics(cmd.OutOrStdout(), b, diags, render.RenderOptions{RenderSummaryTable: true}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| if err1 != nil { | ||
| return err1 | ||
| } | ||
| if diags.HasError() { | ||
| return root.ErrAlreadyPrinted | ||
| } | ||
| return nil | ||
| case flags.OutputJSON: | ||
| renderOpts := render.RenderOptions{RenderSummaryTable: false} | ||
| err1 := render.RenderDiagnostics(cmd.ErrOrStderr(), b, diags, renderOpts) | ||
| err2 := renderJsonOutput(cmd, b) | ||
| if err2 != nil { | ||
| return err2 | ||
| } | ||
| if err1 != nil { | ||
| return err1 | ||
| if root.OutputType(cmd) == flags.OutputJSON { | ||
| err := render.RenderDiagnostics(cmd.ErrOrStderr(), b, diags, render.RenderOptions{RenderSummaryTable: false}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = renderJsonOutput(cmd, b) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| if diags.HasError() { | ||
| return root.ErrAlreadyPrinted | ||
| } | ||
| return nil | ||
| default: | ||
| return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want to keep this default error? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. output type is validated to be text or json, so that line should never be reachable. | ||
| } | ||
| return cmd | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call in if and else conditions are the same, should there be
RenderSummaryTable: truesomewhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the same: stderr for json, stdout for test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, it was difficult to spot