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")
if profileFlag != nil && profileFlag.Value.String() != "" {
profileName = profileFlag.Value.String()
} else {
} else if cmdio.IsInTTY(ctx) {
prompt := cmdio.Prompt(ctx)
prompt.Label = "Databricks Profile Name"
prompt.Default = persistentAuth.ProfileName()
@ -120,6 +120,7 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
cfg.ClusterID = clusterId
}
if profileName != "" {
cfg.Profile = profileName
err = databrickscfg.SaveToProfile(ctx, &cfg)
if err != nil {
@ -127,6 +128,8 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
}
cmdio.LogString(ctx, fmt.Sprintf("Profile %s was successfully saved", profileName))
}
return nil
}