diff --git a/acceptance/cmd/auth/logout/default-profile/output.txt b/acceptance/cmd/auth/logout/default-profile/output.txt index d9a9e0f55d..630ac0b4b9 100644 --- a/acceptance/cmd/auth/logout/default-profile/output.txt +++ b/acceptance/cmd/auth/logout/default-profile/output.txt @@ -11,7 +11,7 @@ host = https://dev.cloud.databricks.com auth_type = databricks-cli === Delete the DEFAULT profile ->>> [CLI] auth logout --profile DEFAULT --force --delete +>>> [CLI] auth logout --profile DEFAULT --yes --delete Logged out of and deleted profile "DEFAULT". === Backup file should exist diff --git a/acceptance/cmd/auth/logout/default-profile/script b/acceptance/cmd/auth/logout/default-profile/script index 94aeda31fa..79c9d48426 100644 --- a/acceptance/cmd/auth/logout/default-profile/script +++ b/acceptance/cmd/auth/logout/default-profile/script @@ -16,7 +16,7 @@ title "Initial config\n" cat "./home/.databrickscfg" title "Delete the DEFAULT profile" -trace $CLI auth logout --profile DEFAULT --force --delete +trace $CLI auth logout --profile DEFAULT --yes --delete title "Backup file should exist\n" assert_backup_exists diff --git a/acceptance/cmd/auth/logout/delete-clears-default/output.txt b/acceptance/cmd/auth/logout/delete-clears-default/output.txt index 6178570d30..c943f9fa7e 100644 --- a/acceptance/cmd/auth/logout/delete-clears-default/output.txt +++ b/acceptance/cmd/auth/logout/delete-clears-default/output.txt @@ -4,14 +4,14 @@ default_profile = workspace-a === Delete the default profile ->>> [CLI] auth logout --profile workspace-a --force --delete +>>> [CLI] auth logout --profile workspace-a --yes --delete Deleted profile "workspace-a" with no tokens to clear. === Settings after deleting default — default_profile should be cleared [__settings__] === Delete a non-default profile ->>> [CLI] auth logout --profile workspace-b --force --delete +>>> [CLI] auth logout --profile workspace-b --yes --delete Deleted profile "workspace-b" with no tokens to clear. === Settings after deleting non-default — section should still be present but empty diff --git a/acceptance/cmd/auth/logout/delete-clears-default/script b/acceptance/cmd/auth/logout/delete-clears-default/script index e378990aee..a2e9473abd 100644 --- a/acceptance/cmd/auth/logout/delete-clears-default/script +++ b/acceptance/cmd/auth/logout/delete-clears-default/script @@ -22,13 +22,13 @@ title "Initial settings section\n" cat "./home/.databrickscfg" | grep -A1 __settings__ title "Delete the default profile" -trace $CLI auth logout --profile workspace-a --force --delete +trace $CLI auth logout --profile workspace-a --yes --delete title "Settings after deleting default — default_profile should be cleared\n" cat "./home/.databrickscfg" | grep -A1 __settings__ title "Delete a non-default profile" -trace $CLI auth logout --profile workspace-b --force --delete +trace $CLI auth logout --profile workspace-b --yes --delete title "Settings after deleting non-default — section should still be present but empty\n" cat "./home/.databrickscfg" | grep -A1 __settings__ diff --git a/acceptance/cmd/auth/logout/delete-pat-token-profile/output.txt b/acceptance/cmd/auth/logout/delete-pat-token-profile/output.txt index a18c4bd75e..a35535f0a0 100644 --- a/acceptance/cmd/auth/logout/delete-pat-token-profile/output.txt +++ b/acceptance/cmd/auth/logout/delete-pat-token-profile/output.txt @@ -8,7 +8,7 @@ host = https://dev.cloud.databricks.com token = dev-pat-token === Logout without --delete — should report no changes for non-U2M profile ->>> [CLI] auth logout --profile dev --force +>>> [CLI] auth logout --profile dev --yes No tokens to clear for profile "dev". Use --delete to remove it from the config file. === Config after logout — profile should be unchanged @@ -20,7 +20,7 @@ host = https://dev.cloud.databricks.com token = dev-pat-token === Logout with --delete — should delete the profile ->>> [CLI] auth logout --profile dev --force --delete +>>> [CLI] auth logout --profile dev --yes --delete Deleted profile "dev" with no tokens to clear. === Backup file should exist diff --git a/acceptance/cmd/auth/logout/delete-pat-token-profile/script b/acceptance/cmd/auth/logout/delete-pat-token-profile/script index e7216bcb0b..b45439139c 100644 --- a/acceptance/cmd/auth/logout/delete-pat-token-profile/script +++ b/acceptance/cmd/auth/logout/delete-pat-token-profile/script @@ -13,13 +13,13 @@ title "Initial config\n" cat "./home/.databrickscfg" title "Logout without --delete — should report no changes for non-U2M profile" -trace $CLI auth logout --profile dev --force +trace $CLI auth logout --profile dev --yes title "Config after logout — profile should be unchanged\n" cat "./home/.databrickscfg" title "Logout with --delete — should delete the profile" -trace $CLI auth logout --profile dev --force --delete +trace $CLI auth logout --profile dev --yes --delete title "Backup file should exist\n" assert_backup_exists diff --git a/acceptance/cmd/auth/logout/error-cases/script b/acceptance/cmd/auth/logout/error-cases/script index cc133e804a..255cfa0aee 100644 --- a/acceptance/cmd/auth/logout/error-cases/script +++ b/acceptance/cmd/auth/logout/error-cases/script @@ -10,7 +10,7 @@ auth_type = databricks-cli EOF title "Logout of non-existent profile\n" -errcode $CLI auth logout --profile nonexistent --force +errcode $CLI auth logout --profile nonexistent --yes title "Logout without --profile in non-interactive mode\n" -errcode $CLI auth logout --force +errcode $CLI auth logout --yes diff --git a/acceptance/cmd/auth/logout/last-non-default/output.txt b/acceptance/cmd/auth/logout/last-non-default/output.txt index 9ecc994c4f..6d80158ea4 100644 --- a/acceptance/cmd/auth/logout/last-non-default/output.txt +++ b/acceptance/cmd/auth/logout/last-non-default/output.txt @@ -9,7 +9,7 @@ host = https://only.cloud.databricks.com auth_type = databricks-cli === Delete the only non-default profile ->>> [CLI] auth logout --profile only-profile --force --delete +>>> [CLI] auth logout --profile only-profile --yes --delete Logged out of and deleted profile "only-profile". === Backup file should exist diff --git a/acceptance/cmd/auth/logout/last-non-default/script b/acceptance/cmd/auth/logout/last-non-default/script index 095c4577ac..d4aff9f5e6 100644 --- a/acceptance/cmd/auth/logout/last-non-default/script +++ b/acceptance/cmd/auth/logout/last-non-default/script @@ -14,7 +14,7 @@ title "Initial config\n" cat "./home/.databrickscfg" title "Delete the only non-default profile" -trace $CLI auth logout --profile only-profile --force --delete +trace $CLI auth logout --profile only-profile --yes --delete title "Backup file should exist\n" assert_backup_exists diff --git a/acceptance/cmd/auth/logout/ordering-preserved/output.txt b/acceptance/cmd/auth/logout/ordering-preserved/output.txt index 2d1a684254..212b04ca9f 100644 --- a/acceptance/cmd/auth/logout/ordering-preserved/output.txt +++ b/acceptance/cmd/auth/logout/ordering-preserved/output.txt @@ -22,7 +22,7 @@ account_id = account-id auth_type = databricks-cli === Delete first non-default profile (alpha) ->>> [CLI] auth logout --profile alpha --force --delete +>>> [CLI] auth logout --profile alpha --yes --delete Logged out of and deleted profile "alpha". === Backup file should exist @@ -46,7 +46,7 @@ account_id = account-id auth_type = databricks-cli === Delete last profile (gamma) ->>> [CLI] auth logout --profile gamma --force --delete +>>> [CLI] auth logout --profile gamma --yes --delete Logged out of and deleted profile "gamma". === Config after deleting gamma diff --git a/acceptance/cmd/auth/logout/ordering-preserved/script b/acceptance/cmd/auth/logout/ordering-preserved/script index 857135b7c9..45e03a6a7b 100644 --- a/acceptance/cmd/auth/logout/ordering-preserved/script +++ b/acceptance/cmd/auth/logout/ordering-preserved/script @@ -27,7 +27,7 @@ title "Initial config\n" cat "./home/.databrickscfg" title "Delete first non-default profile (alpha)" -trace $CLI auth logout --profile alpha --force --delete +trace $CLI auth logout --profile alpha --yes --delete title "Backup file should exist\n" assert_backup_exists @@ -36,7 +36,7 @@ title "Config after deleting alpha\n" cat "./home/.databrickscfg" title "Delete last profile (gamma)" -trace $CLI auth logout --profile gamma --force --delete +trace $CLI auth logout --profile gamma --yes --delete title "Config after deleting gamma\n" cat "./home/.databrickscfg" diff --git a/acceptance/cmd/auth/logout/token-only-shared-host/output.txt b/acceptance/cmd/auth/logout/token-only-shared-host/output.txt index 10f1007618..ff8f1afa27 100644 --- a/acceptance/cmd/auth/logout/token-only-shared-host/output.txt +++ b/acceptance/cmd/auth/logout/token-only-shared-host/output.txt @@ -7,7 +7,7 @@ ] === Logout dev without --delete ->>> [CLI] auth logout --profile dev --force +>>> [CLI] auth logout --profile dev --yes Logged out of profile "dev". Use --delete to also remove it from the config file. === Config after logout — both profiles should still exist diff --git a/acceptance/cmd/auth/logout/token-only-shared-host/script b/acceptance/cmd/auth/logout/token-only-shared-host/script index 87ad0b7af8..3b0130d189 100644 --- a/acceptance/cmd/auth/logout/token-only-shared-host/script +++ b/acceptance/cmd/auth/logout/token-only-shared-host/script @@ -38,7 +38,7 @@ title "Token cache keys before logout\n" jq -S '.tokens | keys' "./home/.databricks/token-cache.json" title "Logout dev without --delete" -trace $CLI auth logout --profile dev --force +trace $CLI auth logout --profile dev --yes title "Config after logout — both profiles should still exist\n" cat "./home/.databrickscfg" diff --git a/acceptance/cmd/auth/logout/token-only/output.txt b/acceptance/cmd/auth/logout/token-only/output.txt index 31142e54ec..60b0ad6959 100644 --- a/acceptance/cmd/auth/logout/token-only/output.txt +++ b/acceptance/cmd/auth/logout/token-only/output.txt @@ -6,7 +6,7 @@ ] === Logout without --delete ->>> [CLI] auth logout --profile dev --force +>>> [CLI] auth logout --profile dev --yes Logged out of profile "dev". Use --delete to also remove it from the config file. === Config after logout — profile should still exist diff --git a/acceptance/cmd/auth/logout/token-only/script b/acceptance/cmd/auth/logout/token-only/script index f1071399d3..113a9398ed 100644 --- a/acceptance/cmd/auth/logout/token-only/script +++ b/acceptance/cmd/auth/logout/token-only/script @@ -31,7 +31,7 @@ title "Token cache keys before logout\n" jq -S '.tokens | keys' "./home/.databricks/token-cache.json" title "Logout without --delete" -trace $CLI auth logout --profile dev --force +trace $CLI auth logout --profile dev --yes title "Config after logout — profile should still exist\n" cat "./home/.databrickscfg" diff --git a/cmd/auth/logout.go b/cmd/auth/logout.go index 74febe760c..d0b8e37c1a 100644 --- a/cmd/auth/logout.go +++ b/cmd/auth/logout.go @@ -43,32 +43,31 @@ terminal, you'll be shown a profile picker. In a non-interactive environment (e.g. CI/CD), omitting --profile is an error. 1. If you specify --profile, the command logs out of that profile. In an - interactive terminal you'll be asked to confirm unless --force is set. + interactive terminal you'll be asked to confirm unless --yes is set. 2. If you omit --profile in an interactive terminal, you'll be shown an interactive picker listing all profiles from your configuration file. You can search by profile name, host, or account ID. After selecting a - profile, you'll be asked to confirm unless --force is specified. + profile, you'll be asked to confirm unless --yes is specified. 3. If you omit --profile in a non-interactive environment (e.g. CI/CD pipeline), the command will fail with an error asking you to specify --profile. -4. Use --force to skip the confirmation prompt. This is required when +4. Use --yes to skip the confirmation prompt. This is required when running in non-interactive environments. 5. Use --delete to also remove the selected profile from ~/.databrickscfg.`, } - var force bool - var profileName string var deleteProfile bool - cmd.Flags().BoolVar(&force, "force", false, "Skip confirmation prompt") - cmd.Flags().StringVar(&profileName, "profile", "", "The profile to log out of") cmd.Flags().BoolVar(&deleteProfile, "delete", false, "Delete the profile from the config file") cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() + profileName := cmd.Flag("profile").Value.String() + yes, _ := cmd.Flags().GetBool("yes") + if profileName == "" { if !cmdio.IsPromptSupported(ctx) { return errors.New("the command is being run in a non-interactive environment, please specify a profile to log out of using --profile") @@ -98,7 +97,7 @@ environment (e.g. CI/CD), omitting --profile is an error. return runLogout(ctx, logoutArgs{ profileName: profileName, - force: force, + yes: yes, deleteProfile: deleteProfile, profiler: profile.DefaultProfiler, tokenCache: tokenCache, @@ -111,7 +110,7 @@ environment (e.g. CI/CD), omitting --profile is an error. type logoutArgs struct { profileName string - force bool + yes bool deleteProfile bool profiler profile.Profiler tokenCache cache.TokenCache @@ -124,9 +123,9 @@ func runLogout(ctx context.Context, args logoutArgs) error { return err } - if !args.force { + if !args.yes { if !cmdio.IsPromptSupported(ctx) { - return errors.New("please specify --force to skip confirmation in non-interactive mode") + return errors.New("please specify --yes to skip confirmation in non-interactive mode") } configPath, err := args.profiler.GetPath(ctx) diff --git a/cmd/auth/logout_test.go b/cmd/auth/logout_test.go index ca6b58e556..d689524b81 100644 --- a/cmd/auth/logout_test.go +++ b/cmd/auth/logout_test.go @@ -78,7 +78,7 @@ func TestLogout(t *testing.T) { hostBasedKey string isSharedKey bool isNonU2M bool // true for profiles that are not created by login (PAT, M2M, etc.) - force bool + yes bool deleteProfile bool wantErr string }{ @@ -87,39 +87,39 @@ func TestLogout(t *testing.T) { profileName: "my-workspace", hostBasedKey: "https://my-workspace.cloud.databricks.com", isSharedKey: true, - force: true, + yes: true, }, { name: "existing workspace profile with unique host", profileName: "my-unique-workspace", hostBasedKey: "https://my-unique-workspace.cloud.databricks.com", isSharedKey: false, - force: true, + yes: true, }, { name: "existing account profile", profileName: "my-account", hostBasedKey: "https://accounts.cloud.databricks.com/oidc/accounts/abc123", isSharedKey: false, - force: true, + yes: true, }, { name: "existing unified profile", profileName: "my-unified", hostBasedKey: "https://unified.cloud.databricks.com/oidc/accounts/def456", isSharedKey: false, - force: true, + yes: true, }, { - name: "existing workspace profile without force in non-interactive mode", + name: "existing workspace profile without yes in non-interactive mode", profileName: "my-workspace", - force: false, - wantErr: "please specify --force to skip confirmation in non-interactive mode", + yes: false, + wantErr: "please specify --yes to skip confirmation in non-interactive mode", }, { name: "non-existing workspace profile", profileName: "nonexistent", - force: false, + yes: false, wantErr: `profile "nonexistent" not found`, }, { @@ -127,7 +127,7 @@ func TestLogout(t *testing.T) { profileName: "my-workspace", hostBasedKey: "https://my-workspace.cloud.databricks.com", isSharedKey: true, - force: true, + yes: true, deleteProfile: true, }, { @@ -135,7 +135,7 @@ func TestLogout(t *testing.T) { profileName: "my-unique-workspace", hostBasedKey: "https://my-unique-workspace.cloud.databricks.com", isSharedKey: false, - force: true, + yes: true, deleteProfile: true, }, { @@ -143,7 +143,7 @@ func TestLogout(t *testing.T) { profileName: "my-account", hostBasedKey: "https://accounts.cloud.databricks.com/oidc/accounts/abc123", isSharedKey: false, - force: true, + yes: true, deleteProfile: true, }, { @@ -151,7 +151,7 @@ func TestLogout(t *testing.T) { profileName: "my-unified", hostBasedKey: "https://unified.cloud.databricks.com/oidc/accounts/def456", isSharedKey: false, - force: true, + yes: true, deleteProfile: true, }, { @@ -159,7 +159,7 @@ func TestLogout(t *testing.T) { profileName: "my-m2m", hostBasedKey: "https://my-m2m.cloud.databricks.com", isNonU2M: true, - force: true, + yes: true, deleteProfile: false, }, } @@ -176,7 +176,7 @@ func TestLogout(t *testing.T) { err := runLogout(ctx, logoutArgs{ profileName: tc.profileName, - force: tc.force, + yes: tc.yes, deleteProfile: tc.deleteProfile, profiler: profile.DefaultProfiler, tokenCache: tokenCache, @@ -225,7 +225,7 @@ func TestLogoutNoTokens(t *testing.T) { err := runLogout(ctx, logoutArgs{ profileName: "my-workspace", - force: true, + yes: true, profiler: profile.DefaultProfiler, tokenCache: tokenCache, configFilePath: configPath, @@ -249,7 +249,7 @@ func TestLogoutNoTokensWithDelete(t *testing.T) { err := runLogout(ctx, logoutArgs{ profileName: "my-workspace", - force: true, + yes: true, deleteProfile: true, profiler: profile.DefaultProfiler, tokenCache: tokenCache, @@ -304,7 +304,7 @@ default_profile = my-workspace err := runLogout(ctx, logoutArgs{ profileName: tc.profileName, - force: true, + yes: true, deleteProfile: true, profiler: profile.DefaultProfiler, tokenCache: tokenCache,