Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/pkg/cli/command/config/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ func NewConfigCmd() *cobra.Command {
Long: configHelp,
}

cmd.AddCommand(NewSetColorCmd())
cmd.AddCommand(NewSetApiKeyCmd())
// Primary commands
cmd.AddCommand(NewGetCmd())
cmd.AddCommand(NewSetCmd())
cmd.AddCommand(NewUnsetCmd())
cmd.AddCommand(NewListCmd())
cmd.AddCommand(NewDescribeCmd())

// Deprecated aliases kept for backwards compatibility
cmd.AddCommand(NewGetApiKeyCmd())
cmd.AddCommand(NewSetApiKeyCmd())
cmd.AddCommand(NewSetColorCmd())
cmd.AddCommand(NewSetEnvCmd())

return cmd
Expand Down
89 changes: 89 additions & 0 deletions internal/pkg/cli/command/config/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package config

import (
"fmt"
"os"
"strings"

"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
"github.com/pinecone-io/cli/internal/pkg/utils/text"
"github.com/spf13/cobra"
)

type DescribeCmdOptions struct {
reveal bool
json bool
}

func NewDescribeCmd() *cobra.Command {
options := DescribeCmdOptions{}

cmd := &cobra.Command{
Use: "describe <key>",
Short: "Show detailed information about a configuration setting",
Example: help.Examples(`
pc config describe api-key
pc config describe environment
pc config describe color --json
`),
Args: cobra.ExactArgs(1),
ValidArgs: configKeyOrder,
Run: func(cmd *cobra.Command, args []string) {
keyName := args[0]
keyDesc, err := lookupKey(keyName)
if err != nil {
msg.FailMsg("%s", err)
exit.ErrorMsg(err.Error())
return
}

value := keyDesc.getStr()
if keyDesc.Sensitive && !options.reveal {
value = presenters.MaskHeadTail(value, 4, 4)
}

if options.json {
type payload struct {
Key string `json:"key"`
Value string `json:"value"`
Description string `json:"description"`
LongDescription string `json:"long_description,omitempty"`
Sensitive bool `json:"sensitive"`
ValidValues []string `json:"valid_values,omitempty"`
}
fmt.Fprintln(os.Stdout, text.IndentJSON(payload{
Key: keyName,
Value: value,
Description: keyDesc.Description,
LongDescription: keyDesc.LongDescription,
Sensitive: keyDesc.Sensitive,
ValidValues: keyDesc.ValidValues,
}))
return
}

w := presenters.NewTabWriter()
fmt.Fprintf(w, "KEY\t%s\n", keyName)
fmt.Fprintf(w, "VALUE\t%s\n", displayValue(value))
fmt.Fprintf(w, "SENSITIVE\t%s\n", text.BoolToString(keyDesc.Sensitive))
if len(keyDesc.ValidValues) > 0 {
fmt.Fprintf(w, "VALID VALUES\t%s\n", strings.Join(keyDesc.ValidValues, ", "))
}
fmt.Fprintf(w, "DESCRIPTION\t%s\n", keyDesc.Description)
w.Flush()

if keyDesc.LongDescription != "" {
fmt.Fprintln(os.Stdout)
fmt.Fprintln(os.Stdout, keyDesc.LongDescription)
}
},
}

cmd.Flags().BoolVar(&options.reveal, "reveal", false, "Reveal the full value for sensitive settings like api-key")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output as JSON")

return cmd
}
65 changes: 65 additions & 0 deletions internal/pkg/cli/command/config/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package config

import (
"fmt"
"os"

"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
"github.com/pinecone-io/cli/internal/pkg/utils/style"
"github.com/pinecone-io/cli/internal/pkg/utils/text"
"github.com/spf13/cobra"
)

type GetCmdOptions struct {
reveal bool
json bool
}

func NewGetCmd() *cobra.Command {
options := GetCmdOptions{}

cmd := &cobra.Command{
Use: "get <key>",
Short: "Get the current value of a configuration setting",
Example: help.Examples(`
pc config get api-key
pc config get api-key --reveal
pc config get environment
pc config get color
`),
Args: cobra.ExactArgs(1),
ValidArgs: configKeyOrder,
Run: func(cmd *cobra.Command, args []string) {
keyName := args[0]
keyDesc, err := lookupKey(keyName)
if err != nil {
msg.FailMsg("%s", err)
exit.ErrorMsg(err.Error())
return
}

value := keyDesc.getStr()
if keyDesc.Sensitive && !options.reveal {
value = presenters.MaskHeadTail(value, 4, 4)
}

if options.json {
fmt.Fprintln(os.Stdout, text.IndentJSON(struct {
Key string `json:"key"`
Value string `json:"value"`
}{Key: keyName, Value: value}))
return
}

msg.InfoMsg("%s: %s", style.Emphasis(keyName), displayValue(value))
},
}

cmd.Flags().BoolVar(&options.reveal, "reveal", false, "Reveal the full value for sensitive settings like api-key")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output as JSON")

return cmd
}
6 changes: 4 additions & 2 deletions internal/pkg/cli/command/config/get_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ func NewGetApiKeyCmd() *cobra.Command {
options := GetAPIKeyCmdOptions{}

cmd := &cobra.Command{
Use: "get-api-key",
Short: "Get the current default API key configured for the Pinecone CLI",
Use: "get-api-key",
Short: "Get the current default API key configured for the Pinecone CLI",
Deprecated: "use 'pc config get api-key' instead",
Hidden: true,
Example: help.Examples(`
pc config get-api-key
`),
Expand Down
72 changes: 72 additions & 0 deletions internal/pkg/cli/command/config/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package config

import (
"fmt"
"os"

"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
"github.com/pinecone-io/cli/internal/pkg/utils/text"
"github.com/spf13/cobra"
)

type ListCmdOptions struct {
reveal bool
json bool
}

func NewListCmd() *cobra.Command {
options := ListCmdOptions{}

cmd := &cobra.Command{
Use: "list",
Short: "List all configuration settings and their current values",
Example: help.Examples(`
pc config list
pc config list --reveal
pc config list --json
`),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
if options.json {
type entry struct {
Key string `json:"key"`
Value string `json:"value"`
Description string `json:"description"`
}
entries := make([]entry, 0, len(configKeyOrder))
for _, keyName := range configKeyOrder {
keyDesc := configRegistry[keyName]
value := keyDesc.getStr()
if keyDesc.Sensitive && !options.reveal {
value = presenters.MaskHeadTail(value, 4, 4)
}
entries = append(entries, entry{
Key: keyName,
Value: value,
Description: keyDesc.Description,
})
}
fmt.Fprintln(os.Stdout, text.IndentJSON(entries))
return
}

w := presenters.NewTabWriter()
fmt.Fprintln(w, "KEY\tVALUE\tDESCRIPTION")
for _, keyName := range configKeyOrder {
keyDesc := configRegistry[keyName]
value := keyDesc.getStr()
if keyDesc.Sensitive && !options.reveal {
value = presenters.MaskHeadTail(value, 4, 4)
}
fmt.Fprintf(w, "%s\t%s\t%s\n", keyName, displayValue(value), keyDesc.Description)
}
w.Flush()
},
}

cmd.Flags().BoolVar(&options.reveal, "reveal", false, "Reveal the full value for sensitive settings like api-key")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output as JSON")

return cmd
}
Loading
Loading