Commit cb3c326
Extract shared SelectProfile helper to eliminate duplicate profile pickers (#4647)
## 🥞 Stacked PR
Use this
[link](https://github.com/databricks/cli/pull/4647/files/e5a1d8842ee9a458d4ffb3cea672a0f88077356f..51f14b5c7ea409cffdc78a3025a70de5c674fa9a)
to review incremental changes.
- [stack/auth_logout](#4613)
[[Files changed](https://github.com/databricks/cli/pull/4613/files)]
-
[stack/auth_logout_profile_picker](#4616)
[[Files
changed](https://github.com/databricks/cli/pull/4616/files/c9e8d79e276d6c33faa1e859ca20cc5136f9efb7..e5a1d8842ee9a458d4ffb3cea672a0f88077356f)]
-
[**stack/auth_logout_deduplication**](#4647)
[[Files
changed](https://github.com/databricks/cli/pull/4647/files/e5a1d8842ee9a458d4ffb3cea672a0f88077356f..51f14b5c7ea409cffdc78a3025a70de5c674fa9a)]
---------
Four places built nearly identical `promptui.Select` prompts for
interactive profile selection (`auth logout`, `auth token`,
`cmd/root/auth.go`, `cmd/root/bundle.go`). This PR extracts a reusable
`profile.SelectProfile` function that accepts a declarative
`SelectConfig` with label, profiles, and template strings, replacing all
four implementations.
## Changes
- Add `profile.SelectProfile` in `libs/databrickscfg/profile/select.go`
— a shared interactive profile picker that accepts a `SelectConfig`
(label, profiles, template strings) and returns the selected profile
name.
- Replace the four inline `promptui.Select` implementations in
`cmd/auth/logout.go`, `cmd/auth/token.go`, `cmd/root/auth.go`, and
`cmd/root/bundle.go` with calls to `SelectProfile`.
- Add `AccountID` to `Profiles.SearchCaseInsensitive` so all pickers
support searching by account ID, not just name and host.
- Extract `writeConfigFile` helper in `libs/databrickscfg/ops.go` to
consolidate the repeated default-comment / backup / save sequence shared
by `SaveToProfile` and `DeleteProfile`.
## Why
The four profile pickers each duplicated the same prompt setup, searcher
wiring, and result extraction. This made it easy for behavior to diverge
(e.g., only the logout picker searched by account ID). A single shared
helper keeps the UX consistent and reduces the surface area for future
changes.
## Tests
- Existing unit and acceptance tests for `auth logout`, `auth token`,
workspace/account profile selection, and bundle profile resolution
continue to pass — the refactor is behavior-preserving.
- The `SelectProfile` helper is exercised indirectly through all
existing callers.
---------
Co-authored-by: simon <simon.faltum@databricks.com>1 parent 70f2d7e commit cb3c326
File tree
38 files changed
+1313
-87
lines changed- acceptance/cmd/auth/logout
- default-profile
- delete-pat-token-profile
- error-cases
- last-non-default
- ordering-preserved
- token-only
- cmd
- auth
- root
- libs/databrickscfg
- profile
38 files changed
+1313
-87
lines changedLines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
0 commit comments