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
4 changes: 2 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ universal_binaries:
- replace: true

archives:
- format: tar.gz
- formats: ["tar.gz"]
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
Expand All @@ -42,7 +42,7 @@ archives:
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
formats: ["zip"]

report_sizes: true

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
2. Install goreleaser

```
brew install goreleaser/tap/goreleaser
brew install --cask goreleaser/tap/goreleaser
```

3. Build the CLI
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/pinecone-io/go-pinecone/v4 v4.1.4
github.com/rs/zerolog v1.32.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
golang.org/x/oauth2 v0.30.0
golang.org/x/term v0.33.0
Expand Down Expand Up @@ -49,7 +50,6 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
Expand Down
15 changes: 8 additions & 7 deletions internal/pkg/cli/command/index/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/index"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
Expand All @@ -19,29 +20,28 @@ type configureIndexOptions struct {
podType string
replicas int32
deletionProtection string

json bool
json bool
}

func NewConfigureIndexCmd() *cobra.Command {
options := configureIndexOptions{}

cmd := &cobra.Command{
Use: "configure",
Use: "configure <name>",
Short: "Configure an existing index with the specified configuration",
Example: "",
Args: index.ValidateIndexNameArgs,
Run: func(cmd *cobra.Command, args []string) {
options.name = args[0]
runConfigureIndexCmd(options)
},
}

// Required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of index to configure")

// Optional flags
cmd.Flags().StringVarP(&options.podType, "pod_type", "t", "", "type of pod to use, can only upgrade when configuring")
cmd.Flags().Int32VarP(&options.replicas, "replicas", "r", 0, "replicas of the index to configure")
cmd.Flags().StringVarP(&options.deletionProtection, "deletion_protection", "p", "", "enable or disable deletion protection for the index")
cmd.Flags().BoolVar(&options.json, "json", false, "output as JSON")

return cmd
}
Expand All @@ -59,13 +59,14 @@ func runConfigureIndexCmd(options configureIndexOptions) {
msg.FailMsg("Failed to configure index %s: %+v\n", style.Emphasis(options.name), err)
exit.Error(err)
}

if options.json {
json := text.IndentJSON(idx)
pcio.Println(json)
return
}

describeCommand := pcio.Sprintf("pc index describe --name %s", idx.Name)
describeCommand := pcio.Sprintf("pc index describe %s", idx.Name)
msg.SuccessMsg("Index %s configured successfully. Run %s to check status. \n\n", style.Emphasis(idx.Name), style.Code(describeCommand))
presenters.PrintDescribeIndexTable(idx)
}
82 changes: 82 additions & 0 deletions internal/pkg/cli/command/index/configure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package index

import (
"testing"

"github.com/pinecone-io/cli/internal/pkg/utils/testutils"
)

func TestConfigureCmd_ArgsValidation(t *testing.T) {
cmd := NewConfigureIndexCmd()

// Get preset index name validation tests
tests := testutils.GetIndexNameValidationTests()

// Add custom tests for this command (configure-specific flags)
customTests := []testutils.CommandTestConfig{
{
Name: "valid - positional arg with --json flag",
Args: []string{"my-index"},
Flags: map[string]string{"json": "true"},
ExpectError: false,
},
{
Name: "valid - positional arg with --json=false",
Args: []string{"my-index"},
Flags: map[string]string{"json": "false"},
ExpectError: false,
},
{
Name: "valid - positional arg with --pod_type flag",
Args: []string{"my-index"},
Flags: map[string]string{"pod_type": "p1.x1"},
ExpectError: false,
},
{
Name: "valid - positional arg with --replicas flag",
Args: []string{"my-index"},
Flags: map[string]string{"replicas": "2"},
ExpectError: false,
},
{
Name: "valid - positional arg with --deletion_protection flag",
Args: []string{"my-index"},
Flags: map[string]string{"deletion_protection": "enabled"},
ExpectError: false,
},
{
Name: "error - no arguments but with --json flag",
Args: []string{},
Flags: map[string]string{"json": "true"},
ExpectError: true,
ErrorSubstr: "please provide an index name",
},
{
Name: "error - multiple arguments with --json flag",
Args: []string{"index1", "index2"},
Flags: map[string]string{"json": "true"},
ExpectError: true,
ErrorSubstr: "please provide only one index name",
},
}

// Combine preset tests with custom tests
allTests := append(tests, customTests...)

// Use the generic test utility
testutils.TestCommandArgsAndFlags(t, cmd, allTests)
}

func TestConfigureCmd_Flags(t *testing.T) {
cmd := NewConfigureIndexCmd()

// Test that the command has a properly configured --json flag
testutils.AssertJSONFlag(t, cmd)
}

func TestConfigureCmd_Usage(t *testing.T) {
cmd := NewConfigureIndexCmd()

// Test that the command has proper usage metadata
testutils.AssertCommandUsage(t, cmd, "configure <name>", "index")
}
17 changes: 8 additions & 9 deletions internal/pkg/cli/command/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/pinecone-io/cli/internal/pkg/utils/docslinks"
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/index"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
Expand Down Expand Up @@ -65,7 +66,7 @@ func NewCreateIndexCmd() *cobra.Command {
options := createIndexOptions{}

cmd := &cobra.Command{
Use: "create",
Use: "create <name>",
Short: "Create a new index with the specified configuration",
Long: heredoc.Docf(`
The %s command creates a new index with the specified configuration. There are several different types of indexes
Expand All @@ -80,23 +81,21 @@ func NewCreateIndexCmd() *cobra.Command {
`, style.Code("pc index create"), style.URL(docslinks.DocsIndexCreate)),
Example: heredoc.Doc(`
# create a serverless index
$ pc index create --name my-index --dimension 1536 --metric cosine --cloud aws --region us-east-1
$ pc index create my-index --dimension 1536 --metric cosine --cloud aws --region us-east-1

# create a pod index
$ pc index create --name my-index --dimension 1536 --metric cosine --environment us-east-1-aws --pod-type p1.x1 --shards 2 --replicas 2
$ pc index create my-index --dimension 1536 --metric cosine --environment us-east-1-aws --pod-type p1.x1 --shards 2 --replicas 2

# create an integrated index
$ pc index create --name my-index --dimension 1536 --metric cosine --cloud aws --region us-east-1 --model multilingual-e5-large --field_map text=chunk_text
$ pc index create my-index --dimension 1536 --metric cosine --cloud aws --region us-east-1 --model multilingual-e5-large --field_map text=chunk_text
`),
Args: index.ValidateIndexNameArgs,
Run: func(cmd *cobra.Command, args []string) {
options.name = args[0]
runCreateIndexCmd(options)
},
}

// Required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Name of index to create")
_ = cmd.MarkFlagRequired("name")

// Serverless & Pods
cmd.Flags().StringVar(&options.sourceCollection, "source_collection", "", "When creating an index from a collection")

Expand Down Expand Up @@ -243,7 +242,7 @@ func renderSuccessOutput(idx *pinecone.Index, options createIndexOptions) {
return
}

describeCommand := pcio.Sprintf("pc index describe --name %s", idx.Name)
describeCommand := pcio.Sprintf("pc index describe %s", idx.Name)
msg.SuccessMsg("Index %s created successfully. Run %s to check status. \n\n", style.Emphasis(idx.Name), style.Code(describeCommand))
presenters.PrintDescribeIndexTable(idx)
}
Expand Down
100 changes: 100 additions & 0 deletions internal/pkg/cli/command/index/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package index

import (
"testing"

"github.com/pinecone-io/cli/internal/pkg/utils/testutils"
)

func TestCreateCmd_ArgsValidation(t *testing.T) {
cmd := NewCreateIndexCmd()

// Get preset index name validation tests
tests := testutils.GetIndexNameValidationTests()

// Add custom tests for this command (create-specific flags)
customTests := []testutils.CommandTestConfig{
{
Name: "valid - positional arg with --json flag",
Args: []string{"my-index"},
Flags: map[string]string{"json": "true"},
ExpectError: false,
},
{
Name: "valid - positional arg with --json=false",
Args: []string{"my-index"},
Flags: map[string]string{"json": "false"},
ExpectError: false,
},
{
Name: "valid - positional arg with --dimension flag",
Args: []string{"my-index"},
Flags: map[string]string{"dimension": "1536"},
ExpectError: false,
},
{
Name: "valid - positional arg with --metric flag",
Args: []string{"my-index"},
Flags: map[string]string{"metric": "cosine"},
ExpectError: false,
},
{
Name: "valid - positional arg with --cloud and --region flags",
Args: []string{"my-index"},
Flags: map[string]string{"cloud": "aws", "region": "us-east-1"},
ExpectError: false,
},
{
Name: "valid - positional arg with --environment flag",
Args: []string{"my-index"},
Flags: map[string]string{"environment": "us-east-1-aws"},
ExpectError: false,
},
{
Name: "valid - positional arg with --pod_type flag",
Args: []string{"my-index"},
Flags: map[string]string{"pod_type": "p1.x1"},
ExpectError: false,
},
{
Name: "valid - positional arg with --model flag",
Args: []string{"my-index"},
Flags: map[string]string{"model": "multilingual-e5-large"},
ExpectError: false,
},
{
Name: "error - no arguments but with --json flag",
Args: []string{},
Flags: map[string]string{"json": "true"},
ExpectError: true,
ErrorSubstr: "please provide an index name",
},
{
Name: "error - multiple arguments with --json flag",
Args: []string{"index1", "index2"},
Flags: map[string]string{"json": "true"},
ExpectError: true,
ErrorSubstr: "please provide only one index name",
},
}

// Combine preset tests with custom tests
allTests := append(tests, customTests...)

// Use the generic test utility
testutils.TestCommandArgsAndFlags(t, cmd, allTests)
}

func TestCreateCmd_Flags(t *testing.T) {
cmd := NewCreateIndexCmd()

// Test that the command has a properly configured --json flag
testutils.AssertJSONFlag(t, cmd)
}

func TestCreateCmd_Usage(t *testing.T) {
cmd := NewCreateIndexCmd()

// Test that the command has proper usage metadata
testutils.AssertCommandUsage(t, cmd, "create <name>", "index")
}
9 changes: 4 additions & 5 deletions internal/pkg/cli/command/index/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/index"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/sdk"
"github.com/pinecone-io/cli/internal/pkg/utils/style"
Expand All @@ -19,9 +20,11 @@ func NewDeleteCmd() *cobra.Command {
options := DeleteCmdOptions{}

cmd := &cobra.Command{
Use: "delete",
Use: "delete <name>",
Short: "Delete an index",
Args: index.ValidateIndexNameArgs,
Run: func(cmd *cobra.Command, args []string) {
options.name = args[0]
ctx := context.Background()
pc := sdk.NewPineconeClient()

Expand All @@ -39,9 +42,5 @@ func NewDeleteCmd() *cobra.Command {
},
}

// required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of index to delete")
_ = cmd.MarkFlagRequired("name")

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

import (
"testing"

"github.com/pinecone-io/cli/internal/pkg/utils/testutils"
)

func TestDeleteCmd_ArgsValidation(t *testing.T) {
cmd := NewDeleteCmd()

// Get preset index name validation tests
tests := testutils.GetIndexNameValidationTests()

// Use the generic test utility
testutils.TestCommandArgsAndFlags(t, cmd, tests)
}

func TestDeleteCmd_Usage(t *testing.T) {
cmd := NewDeleteCmd()

// Test that the command has proper usage metadata
testutils.AssertCommandUsage(t, cmd, "delete <name>", "index")
}
Loading
Loading