Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pages": [
{
"displayName": "New Page",
"layout": [],
"name": "[NUMID]"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resources:
dashboards:
custom_key:
display_name: "This is a test dashboard"
warehouse_id: w4r3h0us3
file_path: ../dashboard/custom_key.lvdash.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
>>> [CLI] bundle generate dashboard --existing-path /path/to/dashboard --dashboard-dir out/dashboard --resource-dir out/resource
Writing dashboard to out/dashboard/this_is_a_test_dashboard.lvdash.json
Writing configuration to out/resource/this_is_a_test_dashboard.dashboard.yml

>>> [CLI] bundle generate dashboard --existing-path /path/to/dashboard --key custom_key --dashboard-dir out/dashboard --resource-dir out/resource
Writing dashboard to out/dashboard/custom_key.lvdash.json
Writing configuration to out/resource/custom_key.dashboard.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Test generating dashboard from existing path
trace $CLI bundle generate dashboard --existing-path /path/to/dashboard --dashboard-dir out/dashboard --resource-dir out/resource

trace $CLI bundle generate dashboard --existing-path /path/to/dashboard --key custom_key --dashboard-dir out/dashboard --resource-dir out/resource
11 changes: 10 additions & 1 deletion cmd/bundle/generate/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ func (d *dashboard) generateForExisting(ctx context.Context, b *bundle.Bundle, d
return
}

key := textutil.NormalizeString(dashboard.DisplayName)
// The "key" flag is a persistent flag on the parent "generate" command.
key := d.cmd.Flag("key").Value.String()
if key == "" {
key = textutil.NormalizeString(dashboard.DisplayName)
}
err = d.saveConfiguration(ctx, b, dashboard, key)
if err != nil {
logdiag.LogError(ctx, err)
Expand Down Expand Up @@ -546,6 +550,11 @@ bundle files automatically, useful during active dashboard development.`,
"existing-id",
"resource",
)
cmd.MarkFlagsMutuallyExclusive(
"existing-path",
"existing-id",
"resource",
)
Comment on lines +553 to +557

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen before this? Based on a quick view it seems that previously there was some precedence between flags where some would get ignored. Not good.

However, now we'll throw an error. Is this a breaking changes? What if people are using multiple flags somewhere and it just works for them?


// Watch flag. This is relevant only in combination with the resource flag.
cmd.Flags().BoolVar(&d.watch, "watch", false, `watch for changes to the dashboard and update the configuration`)
Expand Down
18 changes: 18 additions & 0 deletions cmd/bundle/generate/dashboard_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generate

import (
"io"
"testing"

"github.com/databricks/cli/bundle"
Expand Down Expand Up @@ -47,3 +48,20 @@ func TestDashboard_ErrorOnLegacyDashboard(t *testing.T) {
require.Len(t, diags, 1)
assert.Equal(t, "dashboard \"legacy dashboard\" is a legacy dashboard", diags[0].Summary)
}

func TestDashboard_LookupFlagsAreMutuallyExclusive(t *testing.T) {
tests := [][]string{
{"--existing-path", "/path/to/dashboard", "--existing-id", "f00dcafe"},
{"--existing-path", "/path/to/dashboard", "--resource", "test_dashboard"},
{"--existing-id", "f00dcafe", "--resource", "test_dashboard"},
}

for _, args := range tests {
cmd := NewGenerateDashboardCommand()
cmd.SetArgs(args)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
err := cmd.Execute()
assert.ErrorContains(t, err, "none of the others can be")
}
}
Loading