Skip to content

Commit

Permalink
Prompt for profile only in interactive mode (#788)
Browse files Browse the repository at this point in the history
## 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)
```
  • Loading branch information
andrewnester authored Sep 21, 2023
1 parent 4a9dcd3 commit aa9c2a1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -120,13 +120,16 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
cfg.ClusterID = clusterId
}

cfg.Profile = profileName
err = databrickscfg.SaveToProfile(ctx, &cfg)
if err != nil {
return err
if profileName != "" {
cfg.Profile = profileName
err = databrickscfg.SaveToProfile(ctx, &cfg)
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
}

Expand Down

0 comments on commit aa9c2a1

Please sign in to comment.