Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions acceptance/bundle/summary/show-full-config/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include:
- targets/*.yml

variables:
mode:
default: development
default:
default: false

targets:
also_default:
mode: development
default: true
workspace:
host: https://example.com
5 changes: 5 additions & 0 deletions acceptance/bundle/summary/show-full-config/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions acceptance/bundle/summary/show-full-config/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

>>> [CLI] bundle summary --show-full-config
{
"bundle": {
"name": "test-bundle"
},
"include": [
"targets/default.yml",
"targets/not_default.yml",
"targets/variable_default.yml",
"targets/variable_mode.yml"
],
"targets": {
"also_default": {
"default": true,
"mode": "development",
"workspace": {
"host": "https://example.com"
}
},
"default": {
"default": true,
"mode": "development"
},
"not_default": {
"mode": "production"
},
"variable_default": {
"default": "${var.default}"
},
"variable_mode": {
"mode": "${var.mode}"
}
},
"variables": {
"default": {
"default": false
},
"mode": {
"default": "development"
}
}
}
1 change: 1 addition & 0 deletions acceptance/bundle/summary/show-full-config/script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trace $CLI bundle summary --show-full-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
targets:
default:
mode: development
default: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
targets:
not_default:
mode: production
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
targets:
variable_default:
default: ${var.default}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
targets:
variable_mode:
mode: ${var.mode}
3 changes: 3 additions & 0 deletions acceptance/bundle/summary/show-full-config/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[Repls]]
Old = '\\\\'
New = '/'
68 changes: 55 additions & 13 deletions cmd/bundle/summary.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bundle

import (
"context"
"errors"
"os"
"path/filepath"
Expand Down Expand Up @@ -30,30 +31,28 @@ Useful after deployment to see what was created and where to find it.`,

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
ctx := logdiag.InitContext(cmd.Context())
cmd.SetContext(ctx)
logdiag.SetSeverity(ctx, diag.Warning)

b := prepareBundleForSummary(cmd, forcePull, includeLocations)

if b != nil {
if root.OutputType(cmd) == flags.OutputText {
err = render.RenderSummary(ctx, cmd.OutOrStdout(), b)
if err != nil {
return err
}
if shouldShowFullConfig {
err = showFullConfig(ctx, cmd)
if err != nil {
return err
}
if root.OutputType(cmd) == flags.OutputJSON {
err = renderJsonOutput(cmd, b)
if err != nil {
return err
}
} else {
err = showSummary(ctx, cmd, forcePull, includeLocations)
if err != nil {
return err
}
}

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

func showFullConfig(ctx context.Context, cmd *cobra.Command) 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
}

err := renderJsonOutput(cmd, b)
if err != nil {
return err
}

return nil
}

func showSummary(ctx context.Context, cmd *cobra.Command, forcePull, includeLocations bool) error {
var err error
b := prepareBundleForSummary(cmd, forcePull, includeLocations)

if b != nil {
if root.OutputType(cmd) == flags.OutputText {
err = render.RenderSummary(ctx, cmd.OutOrStdout(), b)
if err != nil {
return err
}
}
if root.OutputType(cmd) == flags.OutputJSON {
err = renderJsonOutput(cmd, b)
if err != nil {
return err
}
}
}

return nil
}

func prepareBundleForSummary(cmd *cobra.Command, forcePull, includeLocations bool) *bundle.Bundle {
b := utils.ConfigureBundleWithVariables(cmd)
ctx := cmd.Context()
Expand Down
Loading