From 22118b52688f9344f1055bd1acf4cf0426e8cc1f Mon Sep 17 00:00:00 2001 From: simonfaltum Date: Tue, 9 Jun 2026 21:47:56 +0200 Subject: [PATCH 1/2] Honor --key in bundle generate dashboard and make lookup flags exclusive The dashboard generator always derived the resource key from the display name even though --key is documented in its help text and honored by the other generate commands. Also enforce that only one of --existing-path, --existing-id, and --resource is provided instead of silently preferring one over the others. Co-authored-by: Isaac --- .../out/dashboard/custom_key.lvdash.json | 9 +++++++++ .../out/resource/custom_key.dashboard.yml | 6 ++++++ .../dashboard_existing_path_nominal/output.txt | 4 ++++ .../dashboard_existing_path_nominal/script | 3 +++ cmd/bundle/generate/dashboard.go | 11 ++++++++++- cmd/bundle/generate/dashboard_test.go | 18 ++++++++++++++++++ 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 acceptance/bundle/generate/dashboard_existing_path_nominal/out/dashboard/custom_key.lvdash.json create mode 100644 acceptance/bundle/generate/dashboard_existing_path_nominal/out/resource/custom_key.dashboard.yml diff --git a/acceptance/bundle/generate/dashboard_existing_path_nominal/out/dashboard/custom_key.lvdash.json b/acceptance/bundle/generate/dashboard_existing_path_nominal/out/dashboard/custom_key.lvdash.json new file mode 100644 index 00000000000..ea901f555c7 --- /dev/null +++ b/acceptance/bundle/generate/dashboard_existing_path_nominal/out/dashboard/custom_key.lvdash.json @@ -0,0 +1,9 @@ +{ + "pages": [ + { + "displayName": "New Page", + "layout": [], + "name": "[NUMID]" + } + ] +} diff --git a/acceptance/bundle/generate/dashboard_existing_path_nominal/out/resource/custom_key.dashboard.yml b/acceptance/bundle/generate/dashboard_existing_path_nominal/out/resource/custom_key.dashboard.yml new file mode 100644 index 00000000000..43eec1b9664 --- /dev/null +++ b/acceptance/bundle/generate/dashboard_existing_path_nominal/out/resource/custom_key.dashboard.yml @@ -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 diff --git a/acceptance/bundle/generate/dashboard_existing_path_nominal/output.txt b/acceptance/bundle/generate/dashboard_existing_path_nominal/output.txt index de3519416c9..dcef0efdf55 100644 --- a/acceptance/bundle/generate/dashboard_existing_path_nominal/output.txt +++ b/acceptance/bundle/generate/dashboard_existing_path_nominal/output.txt @@ -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 diff --git a/acceptance/bundle/generate/dashboard_existing_path_nominal/script b/acceptance/bundle/generate/dashboard_existing_path_nominal/script index 60f26d10841..4a9aaadc642 100644 --- a/acceptance/bundle/generate/dashboard_existing_path_nominal/script +++ b/acceptance/bundle/generate/dashboard_existing_path_nominal/script @@ -1,2 +1,5 @@ # Test generating dashboard from existing path trace $CLI bundle generate dashboard --existing-path /path/to/dashboard --dashboard-dir out/dashboard --resource-dir out/resource + +# Test that --key overrides the key derived from the display name +trace $CLI bundle generate dashboard --existing-path /path/to/dashboard --key custom_key --dashboard-dir out/dashboard --resource-dir out/resource diff --git a/cmd/bundle/generate/dashboard.go b/cmd/bundle/generate/dashboard.go index 2b436cc2dfa..7b5c2a07399 100644 --- a/cmd/bundle/generate/dashboard.go +++ b/cmd/bundle/generate/dashboard.go @@ -340,7 +340,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) @@ -542,6 +546,11 @@ bundle files automatically, useful during active dashboard development.`, "existing-id", "resource", ) + cmd.MarkFlagsMutuallyExclusive( + "existing-path", + "existing-id", + "resource", + ) // 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`) diff --git a/cmd/bundle/generate/dashboard_test.go b/cmd/bundle/generate/dashboard_test.go index d7cb53ad46b..8c346250c8c 100644 --- a/cmd/bundle/generate/dashboard_test.go +++ b/cmd/bundle/generate/dashboard_test.go @@ -1,6 +1,7 @@ package generate import ( + "io" "testing" "github.com/databricks/cli/bundle" @@ -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") + } +} From 4f27d1f42a0e274879000308d5f70cfd55b0bbe3 Mon Sep 17 00:00:00 2001 From: simonfaltum Date: Tue, 9 Jun 2026 23:56:06 +0200 Subject: [PATCH 2/2] Remove redundant comments Co-authored-by: Isaac --- .../bundle/generate/dashboard_existing_path_nominal/script | 1 - 1 file changed, 1 deletion(-) diff --git a/acceptance/bundle/generate/dashboard_existing_path_nominal/script b/acceptance/bundle/generate/dashboard_existing_path_nominal/script index 4a9aaadc642..814370542d9 100644 --- a/acceptance/bundle/generate/dashboard_existing_path_nominal/script +++ b/acceptance/bundle/generate/dashboard_existing_path_nominal/script @@ -1,5 +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 -# Test that --key overrides the key derived from the display name trace $CLI bundle generate dashboard --existing-path /path/to/dashboard --key custom_key --dashboard-dir out/dashboard --resource-dir out/resource