Skip to content

Commit 79f959c

Browse files
authored
Add small UX improvements for databricks configure (#3608)
## Changes 1. Removed the default `https://` prefix in the Host input and always prefixed it if the host input passed with the https:// <img width="366" height="66" alt="Screenshot 2025-09-15 at 16 19 32" src="https://github.com/user-attachments/assets/8a7c42cd-9252-43c1-8201-baebcec680af" /> ## Why Small UX improvements/tweaks <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 9c24734 commit 79f959c

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

cmd/configure/configure.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ func configureInteractive(cmd *cobra.Command, flags *configureFlags, cfg *config
1818
// Ask user to specify the host if not already set.
1919
if cfg.Host == "" {
2020
prompt := cmdio.Prompt(ctx)
21-
prompt.Label = "Databricks host"
22-
prompt.Default = "https://"
21+
prompt.Label = "Databricks workspace host (https://...)"
2322
prompt.AllowEdit = true
24-
prompt.Validate = validateHost
23+
prompt.Validate = func(input string) error {
24+
normalized := normalizeHost(input)
25+
return validateHost(normalized)
26+
}
2527
out, err := prompt.Run()
2628
if err != nil {
2729
return err
2830
}
29-
cfg.Host = out
31+
cfg.Host = normalizeHost(out)
3032
}
3133

3234
// Ask user to specify the token is not already set.
@@ -110,14 +112,15 @@ The host must be specified with the --host flag or the DATABRICKS_HOST environme
110112

111113
// Populate configuration from flags (if set).
112114
if flags.Host != "" {
113-
cfg.Host = flags.Host
115+
cfg.Host = normalizeHost(flags.Host)
114116
}
115117
if flags.Profile != "" {
116118
cfg.Profile = flags.Profile
117119
}
118120

119-
// Verify that the host is valid (if set).
121+
// Normalize and verify that the host is valid (if set).
120122
if cfg.Host != "" {
123+
cfg.Host = normalizeHost(cfg.Host)
121124
err = validateHost(cfg.Host)
122125
if err != nil {
123126
return err

cmd/configure/host.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@ package configure
33
import (
44
"errors"
55
"net/url"
6+
"strings"
67
)
78

9+
// normalizeHost normalizes host input to prevent double https:// prefixes.
10+
// If the input already starts with https://, it returns it as-is.
11+
// If the input doesn't start with https://, it prepends https://.
12+
func normalizeHost(input string) string {
13+
input = strings.TrimSpace(input)
14+
u, err := url.Parse(input)
15+
// If the input is not a valid URL, return it as-is
16+
if err != nil {
17+
return input
18+
}
19+
20+
// If it already starts with https:// or http://, return as-is
21+
if u.Scheme == "https" || u.Scheme == "http" {
22+
return input
23+
}
24+
25+
// Otherwise, prepend https://
26+
return "https://" + input
27+
}
28+
829
func validateHost(s string) error {
930
u, err := url.Parse(s)
1031
if err != nil {

cmd/configure/host_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,41 @@ import (
66
"github.com/stretchr/testify/assert"
77
)
88

9+
func TestNormalizeHost(t *testing.T) {
10+
tests := []struct {
11+
input string
12+
expected string
13+
}{
14+
// Empty input
15+
{"", "https://"},
16+
{" ", "https://"},
17+
18+
// Already has https://
19+
{"https://example.databricks.com", "https://example.databricks.com"},
20+
{"HTTPS://EXAMPLE.DATABRICKS.COM", "HTTPS://EXAMPLE.DATABRICKS.COM"},
21+
{"https://example.databricks.com/", "https://example.databricks.com/"},
22+
23+
// Missing protocol (should add https://)
24+
{"example.databricks.com", "https://example.databricks.com"},
25+
{" example.databricks.com ", "https://example.databricks.com"},
26+
{"subdomain.example.databricks.com", "https://subdomain.example.databricks.com"},
27+
28+
// Edge cases
29+
{"https://", "https://"},
30+
{"example.com", "https://example.com"},
31+
{"https://example.databricks.com/path", "https://example.databricks.com/path"},
32+
{"https://example.databricks.com/path/", "https://example.databricks.com/path/"},
33+
{"http://localhost:8080", "http://localhost:8080"},
34+
}
35+
36+
for _, test := range tests {
37+
t.Run(test.input, func(t *testing.T) {
38+
result := normalizeHost(test.input)
39+
assert.Equal(t, test.expected, result)
40+
})
41+
}
42+
}
43+
944
func TestValidateHost(t *testing.T) {
1045
var err error
1146

0 commit comments

Comments
 (0)