Prompt for profile only in interactive mode (#788)

## Changes
Do not prompt for profiles if not in interactive mode

## Tests
Running sample Go code

```
cmd := exec.Command("databricks", "auth", "login", "--host", "***")
out, err := cmd.CombinedOutput()
```
Before the change
```
Error: ^D

exit status 1
```

After
```
No error (empty output)
```
This commit is contained in:
Andrew Nester 2023-09-21 14:38:45 +02:00 committed by GitHub
parent 4a9dcd3231
commit aa9c2a1eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -48,7 +48,7 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
profileFlag := cmd.Flag("profile") profileFlag := cmd.Flag("profile")
if profileFlag != nil && profileFlag.Value.String() != "" { if profileFlag != nil && profileFlag.Value.String() != "" {
profileName = profileFlag.Value.String() profileName = profileFlag.Value.String()
} else { } else if cmdio.IsInTTY(ctx) {
prompt := cmdio.Prompt(ctx) prompt := cmdio.Prompt(ctx)
prompt.Label = "Databricks Profile Name" prompt.Label = "Databricks Profile Name"
prompt.Default = persistentAuth.ProfileName() prompt.Default = persistentAuth.ProfileName()
@ -120,13 +120,16 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
cfg.ClusterID = clusterId cfg.ClusterID = clusterId
} }
cfg.Profile = profileName if profileName != "" {
err = databrickscfg.SaveToProfile(ctx, &cfg) cfg.Profile = profileName
if err != nil { err = databrickscfg.SaveToProfile(ctx, &cfg)
return err if err != nil {
return err
}
cmdio.LogString(ctx, fmt.Sprintf("Profile %s was successfully saved", profileName))
} }
cmdio.LogString(ctx, fmt.Sprintf("Profile %s was successfully saved", profileName))
return nil return nil
} }