Skip to content

Commit ec51221

Browse files
authored
pipelines open: add autocomplete when one pipeline (#3258)
## Changes When there is only one pipeline deployed, it will automatically open that pipeline without specifying the name ## Why Autocompletes open command, like in dry-run and run ## Tests Modified open acceptance test: - Ran open both specifying the name of the pipeline and without Follows #3243
1 parent 74b4c29 commit ec51221

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

acceptance/pipelines/open/output.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11

2-
=== no run key specified
3-
>>> [PIPELINES] open
4-
Error: expected a KEY of the pipeline to open
5-
6-
Exit code: 1
7-
82
=== not deployed yet
9-
>>> [PIPELINES] open test-pipelines-open
3+
>>> [PIPELINES] open
104
Error: pipeline does not have a URL associated with it (has it been deployed?)
115

126
Exit code: 1
@@ -19,6 +13,13 @@ Deployment complete!
1913

2014
=== Modify PATH so that real open is not run
2115
=== open after deployment. This will fail to open browser and complain, that's ok, we only want the message
16+
>>> [PIPELINES] open
17+
Opening browser at [DATABRICKS_URL]/pipelines/[UUID]?o=[NUMID]
18+
Error: exec: "open": cannot run executable found relative to current directory
19+
20+
Exit code (musterr): 1
21+
22+
=== open with KEY, expect same output as opening without KEY
2223
>>> [PIPELINES] open test-pipelines-open
2324
Opening browser at [DATABRICKS_URL]/pipelines/[UUID]?o=[NUMID]
2425
Error: exec: "open": cannot run executable found relative to current directory

acceptance/pipelines/open/script

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
title "no run key specified"
2-
errcode trace $PIPELINES open
3-
41
title "not deployed yet"
5-
errcode trace $PIPELINES open test-pipelines-open
2+
errcode trace $PIPELINES open
63

74
errcode trace $PIPELINES deploy
85

96
title "Modify PATH so that real open is not run"
107
export PATH=.:$PATH
118

129
title "open after deployment. This will fail to open browser and complain, that's ok, we only want the message"
10+
musterr trace $PIPELINES open
11+
12+
title "open with KEY, expect same output as opening without KEY"
1313
musterr trace $PIPELINES open test-pipelines-open

cmd/pipelines/open.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ func promptOpenArgument(ctx context.Context, b *bundle.Bundle) (string, error) {
4141
return key, nil
4242
}
4343

44+
// When no arguments are specified, auto-selects a pipeline if there's exactly one,
45+
// otherwise prompts the user to select a pipeline to open.
4446
func resolveOpenArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, error) {
45-
// If no arguments are specified, prompt the user to select the resource to open.
46-
if len(args) == 0 && cmdio.IsPromptSupported(ctx) {
47-
return promptOpenArgument(ctx, b)
47+
if len(args) == 0 {
48+
if key := autoSelectSinglePipeline(b); key != "" {
49+
return key, nil
50+
}
51+
52+
if cmdio.IsPromptSupported(ctx) {
53+
return promptOpenArgument(ctx, b)
54+
}
4855
}
4956

5057
if len(args) < 1 {

0 commit comments

Comments
 (0)