Skip to content

Commit

Permalink
fix(cmd): make profile list cmd retro-compatible (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemfromspace authored Apr 22, 2024
1 parent 01a0555 commit be8d3cf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/cmd/profile/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
)

// ListOptions represents the options for the list command
type AddOptions struct {
type ListOptions struct {
config config.IConfig
IO *iostreams.IOStreams
}

// NewListCmd returns a new instance of ListCmd
func NewListCmd(f *cmdutil.Factory, runF func(*AddOptions) error) *cobra.Command {
opts := &AddOptions{
func NewListCmd(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
opts := &ListOptions{
IO: f.IOStreams,
config: f.Config,
}
Expand All @@ -47,7 +47,7 @@ func NewListCmd(f *cmdutil.Factory, runF func(*AddOptions) error) *cobra.Command
}

// runListCmd executes the list command
func runListCmd(opts *AddOptions) error {
func runListCmd(opts *ListOptions) error {
profiles := opts.config.ConfiguredProfiles()
if len(profiles) == 0 {
fmt.Fprintln(opts.IO.ErrOut, "No configured profiles")
Expand All @@ -71,7 +71,12 @@ func runListCmd(opts *AddOptions) error {
table.AddField(profile.Name, nil, nil)
table.AddField(profile.ApplicationID, nil, nil)

client := search.NewClient(profile.ApplicationID, profile.APIKey)
apiKey := profile.APIKey
if apiKey == "" {
apiKey = profile.AdminAPIKey // Legacy
}

client := search.NewClient(profile.ApplicationID, apiKey)
res, err := client.ListIndices()
if err != nil {
table.AddField(err.Error(), nil, nil)
Expand Down

0 comments on commit be8d3cf

Please # to comment.