Skip to content
Merged
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
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/backup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewCreateBackupCmd() *cobra.Command {

cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "Name of the index to back up")
cmd.Flags().StringVarP(&options.description, "description", "d", "", "Optional description for the backup")
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Optional name for the backup")
cmd.Flags().StringVar(&options.name, "name", "", "Optional name for the backup")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output as JSON")
_ = cmd.MarkFlagRequired("index-name")

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/cli/command/index/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func NewIndexCmd() *cobra.Command {
Example: help.Examples(`
pc index list
pc index create --name my-index --dimension 1536 --metric cosine --cloud aws --region us-east-1
pc index describe --name my-index
pc index delete --name my-index
pc index describe --index-name my-index
pc index delete --index-name my-index
`),
GroupID: help.GROUP_VECTORDB.ID,
}
Expand Down
23 changes: 15 additions & 8 deletions internal/pkg/cli/command/index/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type configureIndexOptions struct {
// required for index lookup
name string
indexName string

// pods
podType string
Expand Down Expand Up @@ -50,16 +50,23 @@ func NewConfigureIndexCmd() *cobra.Command {
Use: "configure",
Short: "Configure an existing index",
Example: help.Examples(`
pc index configure --name "index-name" --deletion-protection "enabled"
pc index configure --index-name "index-name" --deletion-protection "enabled"
`),
PreRunE: func(cmd *cobra.Command, args []string) error {
if !cmd.Flags().Changed("index-name") && !cmd.Flags().Changed("name") {
return fmt.Errorf("required flag(s) \"index-name\" not set")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
runConfigureIndexCmd(cmd.Context(), cmd, options)
},
}

// Required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Name of index to configure")
_ = cmd.MarkFlagRequired("name")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "Name of index to configure")
cmd.Flags().StringVarP(&options.indexName, "name", "n", "", "Name of index to configure")
_ = cmd.Flags().MarkDeprecated("name", "use --index-name instead")

// pods
cmd.Flags().StringVarP(&options.podType, "pod-type", "t", "", "Type of pod to use, can only upgrade when configuring")
Expand Down Expand Up @@ -119,11 +126,11 @@ func runConfigureIndexCmd(ctx context.Context, cmd *cobra.Command, options confi
// read capacity configuration
readCapacity, err := buildReadCapacityFromFlags(cmd, options.readMode, options.readNodeType, options.readShards, options.readReplicas)
if err != nil {
msg.FailJSON(options.json, "Failed to configure index %s: %+v\n", style.Emphasis(options.name), err)
msg.FailJSON(options.json, "Failed to configure index %s: %+v\n", style.Emphasis(options.indexName), err)
exit.Error(err, "Failed to configure index")
}

idx, err := pc.ConfigureIndex(ctx, options.name, pinecone.ConfigureIndexParams{
idx, err := pc.ConfigureIndex(ctx, options.indexName, pinecone.ConfigureIndexParams{
PodType: options.podType,
Replicas: options.replicas,
DeletionProtection: pinecone.DeletionProtection(options.deletionProtection),
Expand All @@ -132,7 +139,7 @@ func runConfigureIndexCmd(ctx context.Context, cmd *cobra.Command, options confi
Embed: embed,
})
if err != nil {
msg.FailJSON(options.json, "Failed to configure index %s: %+v\n", style.Emphasis(options.name), err)
msg.FailJSON(options.json, "Failed to configure index %s: %+v\n", style.Emphasis(options.indexName), err)
exit.Error(err, "Failed to configure index")
}

Expand All @@ -142,7 +149,7 @@ func runConfigureIndexCmd(ctx context.Context, cmd *cobra.Command, options confi
return
}

describeCommand := fmt.Sprintf("pc index describe --name %s", idx.Name)
describeCommand := fmt.Sprintf("pc index describe --index-name %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)
}
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func renderSuccessOutput(idx *pinecone.Index, options createIndexOptions) {
return
}

describeCommand := fmt.Sprintf("pc index describe --name %s", idx.Name)
describeCommand := fmt.Sprintf("pc index describe --index-name %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
31 changes: 19 additions & 12 deletions internal/pkg/cli/command/index/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
)

type deleteCmdOptions struct {
name string
json bool
indexName string
json bool
}

// DeleteIndexService abstracts the Pinecone Go SDK for unit testing (runDeleteIndexCmd)
Expand All @@ -31,46 +31,53 @@ func NewDeleteCmd() *cobra.Command {
Use: "delete",
Short: "Delete an index by name",
Example: help.Examples(`
pc index delete --name "index-name"
pc index delete --index-name "index-name"
`),
PreRunE: func(cmd *cobra.Command, args []string) error {
if !cmd.Flags().Changed("index-name") && !cmd.Flags().Changed("name") {
return fmt.Errorf("required flag(s) \"index-name\" not set")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
pc := sdk.NewPineconeClient(ctx)

err := runDeleteIndexCmd(ctx, pc, options)
if err != nil {
if strings.Contains(err.Error(), "not found") {
msg.FailJSON(options.json, "The index %s does not exist\n", style.Emphasis(options.name))
exit.Errorf(err, "The index %s does not exist", style.Emphasis(options.name))
msg.FailJSON(options.json, "The index %s does not exist\n", style.Emphasis(options.indexName))
exit.Errorf(err, "The index %s does not exist", style.Emphasis(options.indexName))
} else {
msg.FailJSON(options.json, "Failed to delete index %s: %s\n", style.Emphasis(options.name), err)
exit.Errorf(err, "Failed to delete index %s", style.Emphasis(options.name))
msg.FailJSON(options.json, "Failed to delete index %s: %s\n", style.Emphasis(options.indexName), err)
exit.Errorf(err, "Failed to delete index %s", style.Emphasis(options.indexName))
}
}
},
}

// required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of index to delete")
_ = cmd.MarkFlagRequired("name")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of index to delete")
cmd.Flags().StringVarP(&options.indexName, "name", "n", "", "name of index to delete")
_ = cmd.Flags().MarkDeprecated("name", "use --index-name instead")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output result as JSON")

return cmd
}

func runDeleteIndexCmd(ctx context.Context, svc DeleteIndexService, options deleteCmdOptions) error {
if err := svc.DeleteIndex(ctx, options.name); err != nil {
if err := svc.DeleteIndex(ctx, options.indexName); err != nil {
return err
}

if options.json {
fmt.Println(text.IndentJSON(struct {
Deleted bool `json:"deleted"`
Name string `json:"name"`
}{Deleted: true, Name: options.name}))
}{Deleted: true, Name: options.indexName}))
return nil
}

msg.SuccessMsg("Index %s deleted.\n", style.Emphasis(options.name))
msg.SuccessMsg("Index %s deleted.\n", style.Emphasis(options.indexName))
return nil
}
6 changes: 3 additions & 3 deletions internal/pkg/cli/command/index/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (m *mockDeleteIndexService) DeleteIndex(ctx context.Context, name string) e

func Test_runDeleteIndexCmd_Succeeds(t *testing.T) {
svc := &mockDeleteIndexService{}
opts := deleteCmdOptions{name: "my-index"}
opts := deleteCmdOptions{indexName: "my-index"}

err := runDeleteIndexCmd(context.Background(), svc, opts)

Expand All @@ -31,7 +31,7 @@ func Test_runDeleteIndexCmd_Succeeds(t *testing.T) {

func Test_runDeleteIndexCmd_SucceedsJSON(t *testing.T) {
svc := &mockDeleteIndexService{}
opts := deleteCmdOptions{name: "my-index", json: true}
opts := deleteCmdOptions{indexName: "my-index", json: true}

out := testutils.CaptureStdout(t, func() {
err := runDeleteIndexCmd(context.Background(), svc, opts)
Expand All @@ -43,7 +43,7 @@ func Test_runDeleteIndexCmd_SucceedsJSON(t *testing.T) {

func Test_runDeleteIndexCmd_PropagatesError(t *testing.T) {
svc := &mockDeleteIndexService{deleteErr: errors.New("not found")}
opts := deleteCmdOptions{name: "missing"}
opts := deleteCmdOptions{indexName: "missing"}

err := runDeleteIndexCmd(context.Background(), svc, opts)

Expand Down
27 changes: 17 additions & 10 deletions internal/pkg/cli/command/index/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

type describeCmdOptions struct {
name string
json bool
indexName string
json bool
}

func NewDescribeCmd() *cobra.Command {
Expand All @@ -27,20 +27,26 @@ func NewDescribeCmd() *cobra.Command {
Use: "describe",
Short: "Describe an index by name",
Example: help.Examples(`
pc index describe --name "index-name"
pc index describe --index-name "index-name"
`),
PreRunE: func(cmd *cobra.Command, args []string) error {
if !cmd.Flags().Changed("index-name") && !cmd.Flags().Changed("name") {
return fmt.Errorf("required flag(s) \"index-name\" not set")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
pc := sdk.NewPineconeClient(ctx)

idx, err := pc.DescribeIndex(cmd.Context(), options.name)
idx, err := pc.DescribeIndex(cmd.Context(), options.indexName)
if err != nil {
if strings.Contains(err.Error(), "not found") {
msg.FailJSON(options.json, "The index %s does not exist\n", style.Emphasis(options.name))
exit.Errorf(err, "The index %s does not exist", style.Emphasis(options.name))
msg.FailJSON(options.json, "The index %s does not exist\n", style.Emphasis(options.indexName))
exit.Errorf(err, "The index %s does not exist", style.Emphasis(options.indexName))
} else {
msg.FailJSON(options.json, "Failed to describe index %s: %s\n", style.Emphasis(options.name), err)
exit.Errorf(err, "Failed to describe index %s", style.Emphasis(options.name))
msg.FailJSON(options.json, "Failed to describe index %s: %s\n", style.Emphasis(options.indexName), err)
exit.Errorf(err, "Failed to describe index %s", style.Emphasis(options.indexName))
}
}

Expand All @@ -54,8 +60,9 @@ func NewDescribeCmd() *cobra.Command {
}

// required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of index to describe")
_ = cmd.MarkFlagRequired("name")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of index to describe")
cmd.Flags().StringVarP(&options.indexName, "name", "n", "", "name of index to describe")
_ = cmd.Flags().MarkDeprecated("name", "use --index-name instead")

// optional flags
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "output as JSON")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/describe_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewDescribeIndexStatsCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of index to describe stats for")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of index to describe stats for")
cmd.Flags().VarP(&options.filter, "filter", "f", "metadata filter to apply to the operation (inline JSON, ./path.json, or '-' for stdin)")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "output as JSON")
_ = cmd.MarkFlagRequired("index-name")
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/cli/command/index/import/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func NewCancelImportCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "Name of the index the import belongs to")
cmd.Flags().StringVarP(&options.importId, "id", "i", "", "ID of the import to cancel")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "Name of the index the import belongs to")
cmd.Flags().StringVar(&options.importId, "id", "", "ID of the import to cancel")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output as JSON")
_ = cmd.MarkFlagRequired("index-name")
_ = cmd.MarkFlagRequired("id")
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/cli/command/index/import/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func NewDescribeImportCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "Name of the index the import belongs to")
cmd.Flags().StringVarP(&options.importId, "id", "i", "", "ID of the import to describe")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "Name of the index the import belongs to")
cmd.Flags().StringVar(&options.importId, "id", "", "ID of the import to describe")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output as JSON")
_ = cmd.MarkFlagRequired("index-name")
_ = cmd.MarkFlagRequired("id")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/import/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewListImportsCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "Name of the index to list imports for")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "Name of the index to list imports for")
cmd.Flags().IntVarP(&options.limit, "limit", "l", 0, "Maximum number of imports to return")
cmd.Flags().StringVarP(&options.paginationToken, "pagination-token", "p", "", "Pagination token to continue a previous listing operation")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output as JSON")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/import/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewStartImportCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "Name of the index to import into")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "Name of the index to import into")
cmd.Flags().StringVarP(&options.uri, "uri", "u", "", "URI of the data to import (e.g. s3://bucket/path/)")
cmd.Flags().StringVar(&options.integrationId, "integration-id", "", "Storage integration ID for private buckets")
cmd.Flags().StringVar(&options.errorMode, "error-mode", "", "How to handle record errors: continue (default) or abort")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/namespace/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewCreateNamespaceCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to create the namespace in")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to create the namespace in")
cmd.Flags().StringVar(&options.name, "name", "", "name of the namespace to create")
cmd.Flags().StringSliceVar(&options.metadataSchema, "schema", []string{}, "metadata schema for the namespace")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "output as JSON")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/namespace/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewDeleteNamespaceCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to delete the namespace from")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to delete the namespace from")
cmd.Flags().StringVar(&options.name, "name", "", "name of the namespace to delete")
_ = cmd.MarkFlagRequired("index-name")
_ = cmd.MarkFlagRequired("name")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/namespace/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewDescribeNamespaceCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to describe the namespace from")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to describe the namespace from")
cmd.Flags().StringVar(&options.name, "name", "", "name of the namespace to describe")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "output as JSON")
_ = cmd.MarkFlagRequired("index-name")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/namespace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewListNamespaceCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to list namespaces from")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to list namespaces from")
cmd.Flags().StringVarP(&options.paginationToken, "pagination-token", "p", "", "pagination token to continue a previous listing operation")
cmd.Flags().Uint32VarP(&options.limit, "limit", "l", 0, "maximum number of namespaces to list")
cmd.Flags().StringVar(&options.prefix, "prefix", "", "prefix to filter namespaces by")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/record/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewSearchCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to search")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to search")
cmd.Flags().StringVar(&options.namespace, "namespace", "", "namespace to search")
cmd.Flags().IntVarP(&options.topK, "top-k", "k", defaultSearchTopK, "number of results to return")
cmd.Flags().Var(&options.inputs, "inputs", "query inputs for search (inline JSON, ./path.json, or '-' for stdin); requires integrated embedding")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/record/upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewUpsertCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of index to upsert into")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of index to upsert into")
cmd.Flags().StringVar(&options.namespace, "namespace", "", "namespace to upsert into")
cmd.Flags().StringVar(&options.file, "file", "", "request body JSON or JSONL (inline, ./path.json[l], or '-' for stdin; only one argument may use stdin)")
cmd.Flags().StringVar(&options.file, "body", "", "alias for --file")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/vector/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewDeleteVectorsCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to delete vectors from")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to delete vectors from")
cmd.Flags().StringVar(&options.namespace, "namespace", "", "namespace to delete vectors from")
cmd.Flags().Var(&options.ids, "ids", "IDs of the vectors to delete (inline JSON string array, ./path.json, or '-' for stdin)")
cmd.Flags().Var(&options.filter, "filter", "filter to delete the vectors with (inline JSON, ./path.json, or '-' for stdin)")
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/cli/command/index/vector/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func NewFetchCmd() *cobra.Command {
},
}

cmd.Flags().VarP(&options.ids, "ids", "i", "IDs of vectors to fetch (inline JSON string array, ./path.json, or '-' for stdin)")
cmd.Flags().Var(&options.ids, "ids", "IDs of vectors to fetch (inline JSON string array, ./path.json, or '-' for stdin)")
cmd.Flags().VarP(&options.filter, "filter", "f", "metadata filter to apply to the fetch (inline JSON, ./path.json, or '-' for stdin)")
cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to fetch from")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to fetch from")
Comment thread
cursor[bot] marked this conversation as resolved.
cmd.Flags().StringVar(&options.namespace, "namespace", "", "namespace to fetch from")
cmd.Flags().Uint32VarP(&options.limit, "limit", "l", 0, "maximum number of vectors to fetch")
cmd.Flags().StringVarP(&options.paginationToken, "pagination-token", "p", "", "pagination token to continue a previous listing operation")
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/vector/list_vectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewListVectorsCmd() *cobra.Command {
},
}

cmd.Flags().StringVarP(&options.indexName, "index-name", "n", "", "name of the index to list vectors from")
cmd.Flags().StringVarP(&options.indexName, "index-name", "i", "", "name of the index to list vectors from")
cmd.Flags().StringVar(&options.namespace, "namespace", "", "namespace to list vectors from")
cmd.Flags().Uint32VarP(&options.limit, "limit", "l", 0, "maximum number of vectors to list")
cmd.Flags().StringVarP(&options.paginationToken, "pagination-token", "p", "", "pagination token to continue a previous listing operation")
Expand Down
Loading
Loading