From 9212719b13b03d63f5562d3d69b273435a461f0e Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Thu, 19 Mar 2026 17:49:54 -0400 Subject: [PATCH 1/2] remove pcio package and --quiet flag entirely. update all usages of pcio. to fmt. to standardize output --- internal/pkg/cli/command/apiKey/create.go | 5 +- internal/pkg/cli/command/apiKey/delete.go | 3 +- internal/pkg/cli/command/apiKey/describe.go | 5 +- internal/pkg/cli/command/apiKey/list.go | 18 ++-- internal/pkg/cli/command/apiKey/update.go | 5 +- internal/pkg/cli/command/auth/configure.go | 16 +-- .../pkg/cli/command/auth/local_keys_list.go | 8 +- .../pkg/cli/command/auth/local_keys_prune.go | 5 +- internal/pkg/cli/command/auth/status.go | 4 +- .../pkg/cli/command/backup/backup_test.go | 10 -- internal/pkg/cli/command/backup/create.go | 3 +- internal/pkg/cli/command/backup/describe.go | 3 +- internal/pkg/cli/command/backup/list.go | 3 +- .../pkg/cli/command/backup/restore/cmd.go | 10 +- .../cli/command/backup/restore/describe.go | 6 +- .../pkg/cli/command/backup/restore/list.go | 4 +- .../command/backup/restore/restore_test.go | 9 -- internal/pkg/cli/command/collection/create.go | 7 +- .../pkg/cli/command/collection/delete_test.go | 8 -- .../pkg/cli/command/collection/describe.go | 5 +- internal/pkg/cli/command/collection/list.go | 8 +- .../pkg/cli/command/config/get_api_key.go | 5 +- internal/pkg/cli/command/index/configure.go | 6 +- internal/pkg/cli/command/index/create.go | 27 ++--- internal/pkg/cli/command/index/describe.go | 4 +- .../pkg/cli/command/index/describe_stats.go | 4 +- internal/pkg/cli/command/index/list.go | 12 +-- .../pkg/cli/command/index/namespace/create.go | 6 +- .../cli/command/index/namespace/describe.go | 6 +- .../pkg/cli/command/index/namespace/list.go | 16 +-- .../command/index/namespace/namespace_test.go | 10 -- .../cli/command/index/record/record_test.go | 10 -- .../pkg/cli/command/index/record/search.go | 24 ++--- .../pkg/cli/command/index/record/upsert.go | 26 ++--- .../pkg/cli/command/index/vector/fetch.go | 4 +- .../cli/command/index/vector/list_vectors.go | 4 +- .../pkg/cli/command/index/vector/query.go | 4 +- .../pkg/cli/command/index/vector/update.go | 4 +- .../pkg/cli/command/index/vector/upsert.go | 10 +- .../pkg/cli/command/organization/delete.go | 5 +- .../cli/command/organization/delete_test.go | 8 -- .../pkg/cli/command/organization/describe.go | 5 +- internal/pkg/cli/command/organization/list.go | 8 +- .../pkg/cli/command/organization/update.go | 5 +- internal/pkg/cli/command/project/create.go | 5 +- internal/pkg/cli/command/project/delete.go | 9 +- .../pkg/cli/command/project/delete_test.go | 8 -- internal/pkg/cli/command/project/describe.go | 5 +- internal/pkg/cli/command/project/list.go | 9 +- internal/pkg/cli/command/project/update.go | 5 +- internal/pkg/cli/command/root/root.go | 5 - internal/pkg/cli/command/target/target.go | 38 +++---- internal/pkg/cli/testutils/test_utils.go | 8 -- internal/pkg/utils/configuration/files.go | 3 +- .../pkg/utils/configuration/state/context.go | 10 +- internal/pkg/utils/flags/flags.go | 12 +-- internal/pkg/utils/login/login.go | 50 +++++----- internal/pkg/utils/oauth/token.go | 4 +- internal/pkg/utils/pcio/io.go | 7 -- internal/pkg/utils/pcio/print.go | 81 --------------- internal/pkg/utils/pcio/print_test.go | 64 ------------ .../utils/presenters/api_key_description.go | 12 +-- .../utils/presenters/api_key_with_secret.go | 14 +-- internal/pkg/utils/presenters/auth_status.go | 22 ++--- internal/pkg/utils/presenters/backup.go | 62 ++++++------ .../presenters/collection_description.go | 18 ++-- .../utils/presenters/describe_index_stats.go | 18 ++-- .../pkg/utils/presenters/fetch_vectors.go | 12 +-- .../pkg/utils/presenters/index_description.go | 98 +++++++++---------- internal/pkg/utils/presenters/list_vectors.go | 12 +-- .../utils/presenters/namespace_description.go | 12 +-- .../presenters/organization_description.go | 20 ++-- .../utils/presenters/project_description.go | 18 ++-- .../pkg/utils/presenters/query_vectors.go | 12 +-- .../pkg/utils/presenters/search_records.go | 12 +-- internal/pkg/utils/presenters/tabwriter.go | 5 +- .../pkg/utils/presenters/target_context.go | 14 +-- .../pkg/utils/presenters/update_vector.go | 6 +- internal/pkg/utils/prompt/list.go | 6 +- internal/pkg/utils/sdk/client.go | 8 +- internal/pkg/utils/style/spinner.go | 4 +- internal/pkg/utils/style/typography.go | 5 +- test/e2e/helpers/cli.go | 2 +- 83 files changed, 424 insertions(+), 649 deletions(-) delete mode 100644 internal/pkg/utils/pcio/io.go delete mode 100644 internal/pkg/utils/pcio/print.go delete mode 100644 internal/pkg/utils/pcio/print_test.go diff --git a/internal/pkg/cli/command/apiKey/create.go b/internal/pkg/cli/command/apiKey/create.go index 37a7a382..2b2bd0ed 100644 --- a/internal/pkg/cli/command/apiKey/create.go +++ b/internal/pkg/cli/command/apiKey/create.go @@ -1,13 +1,14 @@ package apiKey import ( + "fmt" + "github.com/pinecone-io/cli/internal/pkg/utils/configuration/secrets" "github.com/pinecone-io/cli/internal/pkg/utils/configuration/state" "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/log" "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" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -96,7 +97,7 @@ func NewCreateApiKeyCmd() *cobra.Command { if options.json { json := text.IndentJSON(keyWithSecret) - pcio.PrintJSON(json) + fmt.Println(json) } else { msg.SuccessMsg("API key %s created successfully.\n", style.Emphasis(keyWithSecret.Key.Name)) presenters.PrintDescribeAPIKeyWithSecretTable(keyWithSecret) diff --git a/internal/pkg/cli/command/apiKey/delete.go b/internal/pkg/cli/command/apiKey/delete.go index 244e6cf2..8da15158 100644 --- a/internal/pkg/cli/command/apiKey/delete.go +++ b/internal/pkg/cli/command/apiKey/delete.go @@ -11,7 +11,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -104,7 +103,7 @@ func confirmDeleteApiKey(apiKeyName string) { msg.WarnMsg("This action cannot be undone.") // Prompt the user - pcio.Print("Do you want to continue? (y/N): ") + fmt.Print("Do you want to continue? (y/N): ") // Read the user's input reader := bufio.NewReader(os.Stdin) diff --git a/internal/pkg/cli/command/apiKey/describe.go b/internal/pkg/cli/command/apiKey/describe.go index 3fa05b01..4d8d0bf5 100644 --- a/internal/pkg/cli/command/apiKey/describe.go +++ b/internal/pkg/cli/command/apiKey/describe.go @@ -1,10 +1,11 @@ package apiKey import ( + "fmt" + "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -39,7 +40,7 @@ func NewDescribeAPIKeyCmd() *cobra.Command { if options.json { json := text.IndentJSON(apiKey) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintDescribeAPIKeyTable(apiKey) } diff --git a/internal/pkg/cli/command/apiKey/list.go b/internal/pkg/cli/command/apiKey/list.go index aa9faa2a..4561b48d 100644 --- a/internal/pkg/cli/command/apiKey/list.go +++ b/internal/pkg/cli/command/apiKey/list.go @@ -1,6 +1,7 @@ package apiKey import ( + "fmt" "sort" "strings" @@ -8,7 +9,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -65,7 +65,7 @@ func NewListKeysCmd() *cobra.Command { if options.json { json := text.IndentJSON(sortedKeys) - pcio.PrintJSON(json) + fmt.Println(json) } else { printTable(sortedKeys) } @@ -78,17 +78,17 @@ func NewListKeysCmd() *cobra.Command { } func printTable(keys []*pinecone.APIKey) { - pcio.Printf("Organization: %s (ID: %s)\n", style.Emphasis(state.TargetOrg.Get().Name), style.Emphasis(state.TargetOrg.Get().Id)) - pcio.Printf("Project: %s (ID: %s)\n", style.Emphasis(state.TargetProj.Get().Name), style.Emphasis(state.TargetProj.Get().Id)) - pcio.Println() - pcio.Println(style.Heading("API Keys")) - pcio.Println() + fmt.Printf("Organization: %s (ID: %s)\n", style.Emphasis(state.TargetOrg.Get().Name), style.Emphasis(state.TargetOrg.Get().Id)) + fmt.Printf("Project: %s (ID: %s)\n", style.Emphasis(state.TargetProj.Get().Name), style.Emphasis(state.TargetProj.Get().Id)) + fmt.Println() + fmt.Println(style.Heading("API Keys")) + fmt.Println() writer := presenters.NewTabWriter() columns := []string{"NAME", "ID", "PROJECT ID", "ROLES"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, key := range keys { values := []string{ @@ -97,7 +97,7 @@ func printTable(keys []*pinecone.APIKey) { key.ProjectId, strings.Join(key.Roles, ", "), } - pcio.Fprintf(writer, strings.Join(values, "\t")+"\n") + fmt.Fprintf(writer, strings.Join(values, "\t")+"\n") } writer.Flush() diff --git a/internal/pkg/cli/command/apiKey/update.go b/internal/pkg/cli/command/apiKey/update.go index 5eb51a74..2a44db7e 100644 --- a/internal/pkg/cli/command/apiKey/update.go +++ b/internal/pkg/cli/command/apiKey/update.go @@ -1,10 +1,11 @@ package apiKey import ( + "fmt" + "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -50,7 +51,7 @@ func NewUpdateAPIKeyCmd() *cobra.Command { if options.json { json := text.IndentJSON(apiKey) - pcio.PrintJSON(json) + fmt.Println(json) return } diff --git a/internal/pkg/cli/command/auth/configure.go b/internal/pkg/cli/command/auth/configure.go index ddca5553..0037bf8a 100644 --- a/internal/pkg/cli/command/auth/configure.go +++ b/internal/pkg/cli/command/auth/configure.go @@ -2,6 +2,7 @@ package auth import ( "context" + "fmt" "io" "os" "strings" @@ -15,7 +16,6 @@ import ( "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/oauth" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/prompt" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" @@ -112,7 +112,7 @@ func Run(ctx context.Context, io IO, opts configureCmdOptions) { } clientSecret = string(secretBytes) } else if opts.promptIfMissing && isTerminal(os.Stdin) { - pcio.Fprint(io.Out, "Client Secret: ") + fmt.Fprint(io.Out, "Client Secret: ") secretBytes, err := term.ReadPassword(int(os.Stdin.Fd())) if err != nil { msg.FailMsg("Error reading client secret from terminal: %+v", err) @@ -175,7 +175,7 @@ func Run(ctx context.Context, io IO, opts configureCmdOptions) { // If the user has no projects, they can create one by running the project create command if len(projects) == 0 { log.Info().Msg("No projects found for service account") - exit.SuccessMsg(pcio.Sprintf("No projects found for service account, you can create a project by running %s", style.Code("pc project create"))) + exit.SuccessMsg(fmt.Sprintf("No projects found for service account, you can create a project by running %s", style.Code("pc project create"))) } // If the user has one project, set it as the target project @@ -240,11 +240,11 @@ func Run(ctx context.Context, io IO, opts configureCmdOptions) { defaultAPIKey := secrets.DefaultAPIKey.Get() targetContext.DefaultAPIKey = presenters.MaskHeadTail(defaultAPIKey, 4, 4) json := text.IndentJSON(targetContext) - pcio.PrintJSON(json) + fmt.Println(json) return } - pcio.Println() + fmt.Println() presenters.PrintTargetContext(state.GetTargetContext()) } @@ -288,15 +288,15 @@ func uiProjectSelector(projects []*pinecone.Project) *pinecone.Project { } m2 := prompt.NewList(projectItems, len(projectItems)+6, "Choose a project to target", func() { - pcio.Println("Exiting without targeting a project.") - pcio.Printf("You can always run %s to set or change a project context later.\n", style.Code("pc target")) + fmt.Println("Exiting without targeting a project.") + fmt.Printf("You can always run %s to set or change a project context later.\n", style.Code("pc target")) exit.Success() }, func(choice string) string { targetProjectName = choice return "Target project: " + choice }) if _, err := tea.NewProgram(m2).Run(); err != nil { - pcio.Println("Error running program:", err) + fmt.Println("Error running program:", err) os.Exit(1) } diff --git a/internal/pkg/cli/command/auth/local_keys_list.go b/internal/pkg/cli/command/auth/local_keys_list.go index eed75948..f9fd5faa 100644 --- a/internal/pkg/cli/command/auth/local_keys_list.go +++ b/internal/pkg/cli/command/auth/local_keys_list.go @@ -1,11 +1,11 @@ package auth import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/configuration/secrets" "github.com/pinecone-io/cli/internal/pkg/utils/help" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/spf13/cobra" @@ -42,7 +42,7 @@ func NewListLocalKeysCmd() *cobra.Command { if options.json { maskedMap := maskForJSON(managedKeys, options.reveal) json := text.IndentJSON(maskedMap) - pcio.PrintJSON(json) + fmt.Println(json) } else { printTable(managedKeys, options.reveal) } @@ -60,7 +60,7 @@ func printTable(managedKeys map[string]secrets.ManagedKey, reveal bool) { columns := []string{"PROJECT ID", "API KEY NAME", "API KEY ID", "API KEY VALUE", "ORIGIN", "ORGANIZATION ID"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for projectId, managedKey := range managedKeys { keyValue := managedKey.Value @@ -68,7 +68,7 @@ func printTable(managedKeys map[string]secrets.ManagedKey, reveal bool) { keyValue = presenters.MaskHeadTail(keyValue, 4, 4) } values := []string{projectId, managedKey.Name, managedKey.Id, keyValue, string(managedKey.Origin), managedKey.OrganizationId} - pcio.Fprintf(writer, strings.Join(values, "\t")+"\n") + fmt.Fprintf(writer, strings.Join(values, "\t")+"\n") } writer.Flush() diff --git a/internal/pkg/cli/command/auth/local_keys_prune.go b/internal/pkg/cli/command/auth/local_keys_prune.go index fd102916..8eb3b203 100644 --- a/internal/pkg/cli/command/auth/local_keys_prune.go +++ b/internal/pkg/cli/command/auth/local_keys_prune.go @@ -12,7 +12,6 @@ import ( "github.com/pinecone-io/cli/internal/pkg/utils/help" "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" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -191,7 +190,7 @@ func confirmPruneKeys(plan []planItem, options pruneLocalKeysCmdOptions) (bool, msg.WarnMsg("This action cannot be undone.") // Prompt the user - pcio.Print("Do you want to continue? (y/N): ") + fmt.Print("Do you want to continue? (y/N): ") // Read the user's input reader := bufio.NewReader(os.Stdin) @@ -215,7 +214,7 @@ func confirmPruneKeys(plan []planItem, options pruneLocalKeysCmdOptions) (bool, func printDryRunPlan(plan []planItem, options pruneLocalKeysCmdOptions) { if options.json { json := text.IndentJSON(plan) - pcio.PrintJSON(json) + fmt.Println(json) } else { for _, key := range plan { if key.onServer { diff --git a/internal/pkg/cli/command/auth/status.go b/internal/pkg/cli/command/auth/status.go index b76de949..e515fe83 100644 --- a/internal/pkg/cli/command/auth/status.go +++ b/internal/pkg/cli/command/auth/status.go @@ -1,6 +1,7 @@ package auth import ( + "fmt" "time" "github.com/pinecone-io/cli/internal/pkg/utils/configuration/config" @@ -10,7 +11,6 @@ import ( "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/oauth" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/spf13/cobra" @@ -99,7 +99,7 @@ func runAuthStatus(cmd *cobra.Command, options authStatusCmdOptions) error { if options.json { json := text.IndentJSON(authStatus) - pcio.PrintJSON(json) + fmt.Println(json) return nil } diff --git a/internal/pkg/cli/command/backup/backup_test.go b/internal/pkg/cli/command/backup/backup_test.go index bf8c2be9..9067f716 100644 --- a/internal/pkg/cli/command/backup/backup_test.go +++ b/internal/pkg/cli/command/backup/backup_test.go @@ -2,10 +2,7 @@ package backup import ( "context" - "os" - "testing" - "github.com/pinecone-io/cli/internal/pkg/cli/testutils" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -52,10 +49,3 @@ func (m *mockBackupService) CreateIndexFromBackup(ctx context.Context, in *pinec m.lastCreateIndexFromBackupReq = in return m.createIndexFromBackupResp, m.createIndexFromBackupErr } - -func TestMain(m *testing.M) { - reset := testutils.SilenceOutput() - code := m.Run() - reset() - os.Exit(code) -} diff --git a/internal/pkg/cli/command/backup/create.go b/internal/pkg/cli/command/backup/create.go index 7253d6f5..4b91de63 100644 --- a/internal/pkg/cli/command/backup/create.go +++ b/internal/pkg/cli/command/backup/create.go @@ -8,7 +8,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -71,7 +70,7 @@ func NewCreateBackupCmd() *cobra.Command { func runCreateBackupCmd(ctx context.Context, svc BackupService, options createBackupCmdOptions) error { if strings.TrimSpace(options.indexName) == "" { - return pcio.Errorf("--index-name is required") + return fmt.Errorf("--index-name is required") } var descPtr *string diff --git a/internal/pkg/cli/command/backup/describe.go b/internal/pkg/cli/command/backup/describe.go index 72f3e0cd..29f57ada 100644 --- a/internal/pkg/cli/command/backup/describe.go +++ b/internal/pkg/cli/command/backup/describe.go @@ -8,7 +8,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -50,7 +49,7 @@ func NewDescribeBackupCmd() *cobra.Command { func runDescribeBackupCmd(ctx context.Context, svc BackupService, options describeBackupCmdOptions) error { if strings.TrimSpace(options.backupId) == "" { - return pcio.Errorf("--id is required") + return fmt.Errorf("--id is required") } resp, err := svc.DescribeBackup(ctx, options.backupId) diff --git a/internal/pkg/cli/command/backup/list.go b/internal/pkg/cli/command/backup/list.go index 9d096f1b..f5cc9c37 100644 --- a/internal/pkg/cli/command/backup/list.go +++ b/internal/pkg/cli/command/backup/list.go @@ -3,10 +3,11 @@ package backup import ( "context" + "fmt" + "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" - "fmt" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" diff --git a/internal/pkg/cli/command/backup/restore/cmd.go b/internal/pkg/cli/command/backup/restore/cmd.go index e06e6c0a..678c7a70 100644 --- a/internal/pkg/cli/command/backup/restore/cmd.go +++ b/internal/pkg/cli/command/backup/restore/cmd.go @@ -2,12 +2,12 @@ package restore import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -85,10 +85,10 @@ func NewRestoreJobCmd() *cobra.Command { func runRestoreJobCmd(ctx context.Context, svc RestoreJobService, options restoreJobCmdOptions) error { if strings.TrimSpace(options.backupId) == "" { - return pcio.Errorf("--id is required") + return fmt.Errorf("--id is required") } if strings.TrimSpace(options.name) == "" { - return pcio.Errorf("--name is required") + return fmt.Errorf("--name is required") } dp, err := parseDeletionProtection(options.deletionProtection) @@ -113,7 +113,7 @@ func runRestoreJobCmd(ctx context.Context, svc RestoreJobService, options restor } if options.json { - pcio.PrintJSON(text.IndentJSON(resp)) + fmt.Println(text.IndentJSON(resp)) return nil } @@ -133,6 +133,6 @@ func parseDeletionProtection(input string) (*pinecone.DeletionProtection, error) case pinecone.DeletionProtectionEnabled, pinecone.DeletionProtectionDisabled: return &val, nil default: - return nil, pcio.Errorf("invalid deletion-protection value %q, must be one of: enabled, disabled", input) + return nil, fmt.Errorf("invalid deletion-protection value %q, must be one of: enabled, disabled", input) } } diff --git a/internal/pkg/cli/command/backup/restore/describe.go b/internal/pkg/cli/command/backup/restore/describe.go index f9e519f3..73483b33 100644 --- a/internal/pkg/cli/command/backup/restore/describe.go +++ b/internal/pkg/cli/command/backup/restore/describe.go @@ -2,12 +2,12 @@ package restore import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -49,7 +49,7 @@ func NewDescribeRestoreJobCmd() *cobra.Command { func runDescribeRestoreJobCmd(ctx context.Context, svc RestoreJobService, options describeRestoreJobCmdOptions) error { if strings.TrimSpace(options.restoreJobId) == "" { - return pcio.Errorf("--id is required") + return fmt.Errorf("--id is required") } resp, err := svc.DescribeRestoreJob(ctx, options.restoreJobId) @@ -58,7 +58,7 @@ func runDescribeRestoreJobCmd(ctx context.Context, svc RestoreJobService, option } if options.json { - pcio.PrintJSON(text.IndentJSON(resp)) + fmt.Println(text.IndentJSON(resp)) } else { presenters.PrintRestoreJob(resp) } diff --git a/internal/pkg/cli/command/backup/restore/list.go b/internal/pkg/cli/command/backup/restore/list.go index fdbb039e..1b2fd7df 100644 --- a/internal/pkg/cli/command/backup/restore/list.go +++ b/internal/pkg/cli/command/backup/restore/list.go @@ -2,11 +2,11 @@ package restore import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -69,7 +69,7 @@ func runListRestoreJobsCmd(ctx context.Context, svc RestoreJobService, options l } if options.json { - pcio.PrintJSON(text.IndentJSON(resp)) + fmt.Println(text.IndentJSON(resp)) } else { presenters.PrintRestoreJobList(resp) } diff --git a/internal/pkg/cli/command/backup/restore/restore_test.go b/internal/pkg/cli/command/backup/restore/restore_test.go index 191f4546..c7228227 100644 --- a/internal/pkg/cli/command/backup/restore/restore_test.go +++ b/internal/pkg/cli/command/backup/restore/restore_test.go @@ -2,11 +2,9 @@ package restore import ( "context" - "os" "testing" "time" - "github.com/pinecone-io/cli/internal/pkg/cli/testutils" "github.com/pinecone-io/go-pinecone/v5/pinecone" "github.com/stretchr/testify/assert" ) @@ -40,13 +38,6 @@ func (m *mockRestoreJobService) CreateIndexFromBackup(ctx context.Context, in *p return m.createIndexFromBackupResp, m.createIndexFromBackupErr } -func TestMain(m *testing.M) { - reset := testutils.SilenceOutput() - code := m.Run() - reset() - os.Exit(code) -} - func Test_runDescribeRestoreJobCmd_RequiresId(t *testing.T) { svc := &mockRestoreJobService{} opts := describeRestoreJobCmdOptions{} diff --git a/internal/pkg/cli/command/collection/create.go b/internal/pkg/cli/command/collection/create.go index 44daacd5..4885a0a4 100644 --- a/internal/pkg/cli/command/collection/create.go +++ b/internal/pkg/cli/command/collection/create.go @@ -1,10 +1,11 @@ package collection import ( + "fmt" + "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -45,9 +46,9 @@ func NewCreateCollectionCmd() *cobra.Command { if options.json { json := text.IndentJSON(collection) - pcio.PrintJSON(json) + fmt.Println(json) } else { - describeCommand := pcio.Sprintf("pc collection describe --name %s", collection.Name) + describeCommand := fmt.Sprintf("pc collection describe --name %s", collection.Name) msg.SuccessMsg("Collection %s created successfully. Run %s to check status. \n\n", style.Emphasis(collection.Name), style.Code(describeCommand)) presenters.PrintDescribeCollectionTable(collection) } diff --git a/internal/pkg/cli/command/collection/delete_test.go b/internal/pkg/cli/command/collection/delete_test.go index e3e51184..9190d2fe 100644 --- a/internal/pkg/cli/command/collection/delete_test.go +++ b/internal/pkg/cli/command/collection/delete_test.go @@ -3,7 +3,6 @@ package collection import ( "context" "errors" - "os" "testing" "github.com/pinecone-io/cli/internal/pkg/cli/testutils" @@ -20,13 +19,6 @@ func (m *mockDeleteCollectionService) DeleteCollection(ctx context.Context, name return m.deleteErr } -func TestMain(m *testing.M) { - reset := testutils.SilenceOutput() - code := m.Run() - reset() - os.Exit(code) -} - func Test_runDeleteCollectionCmd_Succeeds(t *testing.T) { svc := &mockDeleteCollectionService{} opts := deleteCollectionCmdOptions{name: "my-collection"} diff --git a/internal/pkg/cli/command/collection/describe.go b/internal/pkg/cli/command/collection/describe.go index 9214a16c..2cd27e58 100644 --- a/internal/pkg/cli/command/collection/describe.go +++ b/internal/pkg/cli/command/collection/describe.go @@ -1,10 +1,11 @@ package collection import ( + "fmt" + "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -37,7 +38,7 @@ func NewDescribeCollectionCmd() *cobra.Command { if options.json { json := text.IndentJSON(collection) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintDescribeCollectionTable(collection) } diff --git a/internal/pkg/cli/command/collection/list.go b/internal/pkg/cli/command/collection/list.go index 1db99c08..4e3243f1 100644 --- a/internal/pkg/cli/command/collection/list.go +++ b/internal/pkg/cli/command/collection/list.go @@ -1,6 +1,7 @@ package collection import ( + "fmt" "sort" "strconv" "strings" @@ -8,7 +9,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -47,7 +47,7 @@ func NewListCollectionsCmd() *cobra.Command { if options.json { json := text.IndentJSON(collections) - pcio.PrintJSON(json) + fmt.Println(json) } else { printTable(collections) } @@ -65,11 +65,11 @@ func printTable(collections []*pinecone.Collection) { columns := []string{"NAME", "DIMENSION", "SIZE", "STATUS", "VECTORS", "ENVIRONMENT"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, coll := range collections { values := []string{coll.Name, string(coll.Dimension), strconv.FormatInt(coll.Size, 10), string(coll.Status), string(coll.VectorCount), coll.Environment} - pcio.Fprintf(writer, strings.Join(values, "\t")+"\n") + fmt.Fprintf(writer, strings.Join(values, "\t")+"\n") } writer.Flush() } diff --git a/internal/pkg/cli/command/config/get_api_key.go b/internal/pkg/cli/command/config/get_api_key.go index ba3961b6..02af13c3 100644 --- a/internal/pkg/cli/command/config/get_api_key.go +++ b/internal/pkg/cli/command/config/get_api_key.go @@ -1,9 +1,10 @@ package config import ( + "fmt" + "github.com/pinecone-io/cli/internal/pkg/utils/configuration/secrets" "github.com/pinecone-io/cli/internal/pkg/utils/help" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/spf13/cobra" ) @@ -26,7 +27,7 @@ func NewGetApiKeyCmd() *cobra.Command { if !options.reveal { apiKey = presenters.MaskHeadTail(apiKey, 4, 4) } - pcio.Printf("Current default API key: %s", apiKey) + fmt.Printf("Current default API key: %s", apiKey) }, } diff --git a/internal/pkg/cli/command/index/configure.go b/internal/pkg/cli/command/index/configure.go index 41cc9883..28889036 100644 --- a/internal/pkg/cli/command/index/configure.go +++ b/internal/pkg/cli/command/index/configure.go @@ -2,11 +2,11 @@ package index import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -136,11 +136,11 @@ func runConfigureIndexCmd(ctx context.Context, cmd *cobra.Command, options confi if options.json { json := text.IndentJSON(idx) - pcio.PrintJSON(json) + fmt.Println(json) return } - describeCommand := pcio.Sprintf("pc index describe --name %s", idx.Name) + describeCommand := fmt.Sprintf("pc index describe --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) } diff --git a/internal/pkg/cli/command/index/create.go b/internal/pkg/cli/command/index/create.go index b1326d60..a9d922b8 100644 --- a/internal/pkg/cli/command/index/create.go +++ b/internal/pkg/cli/command/index/create.go @@ -2,6 +2,8 @@ package index import ( "context" + "errors" + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/docslinks" @@ -9,7 +11,6 @@ import ( "github.com/pinecone-io/cli/internal/pkg/utils/help" "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" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -219,7 +220,7 @@ func runCreateIndexCmd(ctx context.Context, cmd *cobra.Command, service CreateIn idx, err = service.CreateServerlessIndex(ctx, &args) if err != nil { - wrapped := pcio.Errorf("Failed to create serverless index %s: %w", style.Emphasis(options.name), err) + wrapped := fmt.Errorf("Failed to create serverless index %s: %w", style.Emphasis(options.name), err) return nil, wrapped } case indexTypePod: @@ -247,7 +248,7 @@ func runCreateIndexCmd(ctx context.Context, cmd *cobra.Command, service CreateIn idx, err = service.CreatePodIndex(ctx, &args) if err != nil { - wrapped := pcio.Errorf("Failed to create pod index %s: %w", style.Emphasis(options.name), err) + wrapped := fmt.Errorf("Failed to create pod index %s: %w", style.Emphasis(options.name), err) return nil, wrapped } case indexTypeIntegrated: @@ -278,7 +279,7 @@ func runCreateIndexCmd(ctx context.Context, cmd *cobra.Command, service CreateIn idx, err = service.CreateIndexForModel(ctx, &args) if err != nil { - wrapped := pcio.Errorf("Failed to create integrated index %s: %w", style.Emphasis(options.name), err) + wrapped := fmt.Errorf("Failed to create integrated index %s: %w", style.Emphasis(options.name), err) return nil, wrapped } case indexTypeBYOC: @@ -295,11 +296,11 @@ func runCreateIndexCmd(ctx context.Context, cmd *cobra.Command, service CreateIn idx, err = service.CreateBYOCIndex(ctx, &args) if err != nil { - wrapped := pcio.Errorf("Failed to create BYOC index %s: %w", style.Emphasis(options.name), err) + wrapped := fmt.Errorf("Failed to create BYOC index %s: %w", style.Emphasis(options.name), err) return nil, wrapped } default: - err := pcio.Errorf("Error creating index: invalid index type") + err := fmt.Errorf("Error creating index: invalid index type") return nil, err } @@ -309,11 +310,11 @@ func runCreateIndexCmd(ctx context.Context, cmd *cobra.Command, service CreateIn func renderSuccessOutput(idx *pinecone.Index, options createIndexOptions) { if options.json { json := text.IndentJSON(idx) - pcio.PrintJSON(json) + fmt.Println(json) return } - describeCommand := pcio.Sprintf("pc index describe --name %s", idx.Name) + describeCommand := fmt.Sprintf("pc index describe --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) } @@ -322,14 +323,14 @@ func renderSuccessOutput(idx *pinecone.Index, options createIndexOptions) { func (c *createIndexOptions) validate() error { // name required for all index types if c.name == "" { - err := pcio.Errorf("name is required") + err := fmt.Errorf("name is required") log.Error().Err(err).Msg("Error creating index") return err } // environment and cloud/region cannot be provided together if c.cloud != "" && c.region != "" && c.environment != "" { - err := pcio.Errorf("cloud, region, and environment cannot be provided together") + err := fmt.Errorf("cloud, region, and environment cannot be provided together") log.Error().Err(err).Msg("Error creating index") return err } @@ -352,7 +353,7 @@ func (c *createIndexOptions) deriveIndexType() (indexType, error) { if c.environment != "" { return indexTypePod, nil } - return "", pcio.Error("invalid index type. Please provide either environment, or cloud and region") + return "", errors.New("invalid index type. Please provide either environment, or cloud and region") } // Builds the ReadCapacityParams object based on the provided arguments @@ -389,7 +390,7 @@ func buildReadCapacityFromFlags(cmd *cobra.Command, mode, nodeType string, shard switch normMode { case "ondemand": if nodeSet || shardsSet || replSet { - return nil, pcio.Errorf("read-node-type, read-shards, and read-replicas are not supported with read-mode=ondemand") + return nil, fmt.Errorf("read-node-type, read-shards, and read-replicas are not supported with read-mode=ondemand") } return &pinecone.ReadCapacityParams{ OnDemand: &pinecone.ReadCapacityOnDemandConfig{}, @@ -397,7 +398,7 @@ func buildReadCapacityFromFlags(cmd *cobra.Command, mode, nodeType string, shard case "dedicated": // continue default: - return nil, pcio.Errorf("invalid read-mode") + return nil, fmt.Errorf("invalid read-mode") } } else { // read-mode not provided, return nil if no specific configuration values are passed if !nodeSet && !shardsSet && !replSet { diff --git a/internal/pkg/cli/command/index/describe.go b/internal/pkg/cli/command/index/describe.go index d169a8b7..7ce367c7 100644 --- a/internal/pkg/cli/command/index/describe.go +++ b/internal/pkg/cli/command/index/describe.go @@ -1,12 +1,12 @@ package index import ( + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -45,7 +45,7 @@ func NewDescribeCmd() *cobra.Command { if options.json { json := text.IndentJSON(idx) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintDescribeIndexTable(idx) } diff --git a/internal/pkg/cli/command/index/describe_stats.go b/internal/pkg/cli/command/index/describe_stats.go index 7f731d8f..be028993 100644 --- a/internal/pkg/cli/command/index/describe_stats.go +++ b/internal/pkg/cli/command/index/describe_stats.go @@ -2,12 +2,12 @@ package index import ( "context" + "fmt" "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/flags" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -77,7 +77,7 @@ func runDescribeIndexStatsCmd(ctx context.Context, options describeIndexStatsCmd if options.json { json := text.IndentJSON(resp) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintDescribeIndexStatsTable(resp) } diff --git a/internal/pkg/cli/command/index/list.go b/internal/pkg/cli/command/index/list.go index 5ba4ac75..ff392622 100644 --- a/internal/pkg/cli/command/index/list.go +++ b/internal/pkg/cli/command/index/list.go @@ -1,13 +1,13 @@ package index import ( + "fmt" "sort" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -47,7 +47,7 @@ func NewListCmd() *cobra.Command { if options.json { json := text.IndentJSON(idxs) - pcio.PrintJSON(json) + fmt.Println(json) } else { printTable(idxs, options.wide) } @@ -69,7 +69,7 @@ func printTable(idxs []*pinecone.Index, wide bool) { columns = append(columns, "EMBED", "TAGS") } header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, idx := range idxs { status := "-" @@ -79,7 +79,7 @@ func printTable(idxs []*pinecone.Index, wide bool) { dimension := "nil" if idx.Dimension != nil { - dimension = pcio.Sprintf("%d", *idx.Dimension) + dimension = fmt.Sprintf("%d", *idx.Dimension) } spec := formatSpec(idx.Spec) @@ -93,11 +93,11 @@ func printTable(idxs []*pinecone.Index, wide bool) { if wide { values = append(values, embed, tags) } - pcio.Fprintf(writer, strings.Join(values, "\t")+"\n") + fmt.Fprintf(writer, strings.Join(values, "\t")+"\n") } if !wide { - pcio.Fprint(writer, "\nUse --wide to show host/embed/tags, or --json for full details.\n") + fmt.Fprint(writer, "\nUse --wide to show host/embed/tags, or --json for full details.\n") } writer.Flush() } diff --git a/internal/pkg/cli/command/index/namespace/create.go b/internal/pkg/cli/command/index/namespace/create.go index 51145750..b308c467 100644 --- a/internal/pkg/cli/command/index/namespace/create.go +++ b/internal/pkg/cli/command/index/namespace/create.go @@ -2,12 +2,12 @@ package namespace import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -82,7 +82,7 @@ func NewCreateNamespaceCmd() *cobra.Command { func runCreateNamespaceCmd(ctx context.Context, ic NamespaceService, options createNamespaceCmdOptions) error { if strings.TrimSpace(options.name) == "" { - return pcio.Errorf("--name is required") + return fmt.Errorf("--name is required") } req := &pinecone.CreateNamespaceParams{ @@ -96,7 +96,7 @@ func runCreateNamespaceCmd(ctx context.Context, ic NamespaceService, options cre if options.json { json := text.IndentJSON(ns) - pcio.PrintJSON(json) + fmt.Println(json) } else { msg.SuccessMsg("Namespace %s created successfully.", options.name) presenters.PrintDescribeNamespaceTable(ns) diff --git a/internal/pkg/cli/command/index/namespace/describe.go b/internal/pkg/cli/command/index/namespace/describe.go index 77b371f1..adfeab17 100644 --- a/internal/pkg/cli/command/index/namespace/describe.go +++ b/internal/pkg/cli/command/index/namespace/describe.go @@ -2,12 +2,12 @@ package namespace import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -70,7 +70,7 @@ func NewDescribeNamespaceCmd() *cobra.Command { func runDescribeNamespaceCmd(ctx context.Context, ic NamespaceService, options describeNamespaceCmdOptions) error { if strings.TrimSpace(options.name) == "" { - return pcio.Errorf("--name is required") + return fmt.Errorf("--name is required") } ns, err := ic.DescribeNamespace(ctx, options.name) @@ -80,7 +80,7 @@ func runDescribeNamespaceCmd(ctx context.Context, ic NamespaceService, options d if options.json { json := text.IndentJSON(ns) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintDescribeNamespaceTable(ns) } diff --git a/internal/pkg/cli/command/index/namespace/list.go b/internal/pkg/cli/command/index/namespace/list.go index aaaebf23..8b99ea42 100644 --- a/internal/pkg/cli/command/index/namespace/list.go +++ b/internal/pkg/cli/command/index/namespace/list.go @@ -2,12 +2,12 @@ package namespace import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -82,7 +82,7 @@ func NewListNamespaceCmd() *cobra.Command { func runListNamespaceCmd(ctx context.Context, ic NamespaceService, options listNamespaceCmdOptions) error { if strings.TrimSpace(options.indexName) == "" { - return pcio.Errorf("--index-name is required") + return fmt.Errorf("--index-name is required") } var limit *uint32 @@ -109,7 +109,7 @@ func runListNamespaceCmd(ctx context.Context, ic NamespaceService, options listN if options.json { json := text.IndentJSON(resp) - pcio.PrintJSON(json) + fmt.Println(json) } else { printTable(resp) } @@ -125,18 +125,18 @@ func printTable(resp *pinecone.ListNamespacesResponse) { } // Response info - pcio.Fprintf(writer, "Total Count: %d\n", resp.TotalCount) + fmt.Fprintf(writer, "Total Count: %d\n", resp.TotalCount) pgToken := "" if resp.Pagination != nil && resp.Pagination.Next != "" { pgToken = resp.Pagination.Next } - pcio.Fprintf(writer, "Next Pagination Token: %s\n", pgToken) - pcio.Fprintf(writer, "\n") + fmt.Fprintf(writer, "Next Pagination Token: %s\n", pgToken) + fmt.Fprintf(writer, "\n") // Namespaces table columns := []string{"NAME", "RECORD COUNT", "INDEXED FIELDS", "SCHEMA"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, ns := range resp.Namespaces { schema := "" @@ -147,7 +147,7 @@ func printTable(resp *pinecone.ListNamespacesResponse) { if ns.IndexedFields != nil { indexedFields = text.InlineJSON(ns.IndexedFields) } - pcio.Fprintf(writer, "%s\t%d\t%s\t%s\n", ns.Name, ns.RecordCount, indexedFields, schema) + fmt.Fprintf(writer, "%s\t%d\t%s\t%s\n", ns.Name, ns.RecordCount, indexedFields, schema) } writer.Flush() } diff --git a/internal/pkg/cli/command/index/namespace/namespace_test.go b/internal/pkg/cli/command/index/namespace/namespace_test.go index 30f5ecee..779b3b65 100644 --- a/internal/pkg/cli/command/index/namespace/namespace_test.go +++ b/internal/pkg/cli/command/index/namespace/namespace_test.go @@ -2,10 +2,7 @@ package namespace import ( "context" - "os" - "testing" - "github.com/pinecone-io/cli/internal/pkg/cli/testutils" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -60,10 +57,3 @@ func (m *mockNamespaceService) DeleteNamespace(ctx context.Context, name string) m.lastDeleteArg = name return m.deleteErr } - -func TestMain(m *testing.M) { - reset := testutils.SilenceOutput() - code := m.Run() - reset() - os.Exit(code) -} diff --git a/internal/pkg/cli/command/index/record/record_test.go b/internal/pkg/cli/command/index/record/record_test.go index bbcb1cd0..f811d1cf 100644 --- a/internal/pkg/cli/command/index/record/record_test.go +++ b/internal/pkg/cli/command/index/record/record_test.go @@ -2,10 +2,7 @@ package record import ( "context" - "os" - "testing" - "github.com/pinecone-io/cli/internal/pkg/cli/testutils" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -30,10 +27,3 @@ func (m *mockRecordService) SearchRecords(_ context.Context, req *pinecone.Searc m.lastSearchReq = req return m.searchResp, m.searchErr } - -func TestMain(m *testing.M) { - reset := testutils.SilenceOutput() - code := m.Run() - reset() - os.Exit(code) -} diff --git a/internal/pkg/cli/command/index/record/search.go b/internal/pkg/cli/command/index/record/search.go index 8c800859..e108523f 100644 --- a/internal/pkg/cli/command/index/record/search.go +++ b/internal/pkg/cli/command/index/record/search.go @@ -4,13 +4,13 @@ import ( "bytes" "context" "encoding/json" + "fmt" "github.com/pinecone-io/cli/internal/pkg/utils/argio" "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/flags" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -160,28 +160,28 @@ func runSearchCmd(ctx context.Context, ic RecordService, options searchCmdOption if options.rerank != nil { b, err := json.Marshal(options.rerank) if err != nil { - return pcio.Errorf("failed to encode --rerank value: %w", err) + return fmt.Errorf("failed to encode --rerank value: %w", err) } var rerank pinecone.SearchRecordsRerank if err := json.Unmarshal(b, &rerank); err != nil { - return pcio.Errorf("failed to parse --rerank value: %w", err) + return fmt.Errorf("failed to parse --rerank value: %w", err) } req.Rerank = &rerank } if options.matchTerms != nil { b, err := json.Marshal(options.matchTerms) if err != nil { - return pcio.Errorf("failed to encode --match-terms value: %w", err) + return fmt.Errorf("failed to encode --match-terms value: %w", err) } var matchTerms pinecone.SearchMatchTerms if err := json.Unmarshal(b, &matchTerms); err != nil { - return pcio.Errorf("failed to parse --match-terms value: %w", err) + return fmt.Errorf("failed to parse --match-terms value: %w", err) } req.Query.MatchTerms = &matchTerms } if len(options.vector) > 0 || len(options.sparseIndices) > 0 { if len(options.sparseIndices) != len(options.sparseValues) { - return pcio.Errorf("--sparse-indices and --sparse-values must be the same length") + return fmt.Errorf("--sparse-indices and --sparse-values must be the same length") } sv := &pinecone.SearchRecordsVector{} if len(options.vector) > 0 { @@ -204,14 +204,14 @@ func runSearchCmd(ctx context.Context, ic RecordService, options searchCmdOption if options.body != "" { rawBody, src, err := argio.ReadAll(options.body) if err != nil { - return pcio.Errorf("failed to read search body (%s): %w", style.Emphasis(src.Label), err) + return fmt.Errorf("failed to read search body (%s): %w", style.Emphasis(src.Label), err) } var bodyReq pinecone.SearchRecordsRequest dec := json.NewDecoder(bytes.NewReader(rawBody)) dec.DisallowUnknownFields() if err := dec.Decode(&bodyReq); err != nil { - return pcio.Errorf("failed to parse search body (%s): %w", style.Emphasis(src.Label), err) + return fmt.Errorf("failed to parse search body (%s): %w", style.Emphasis(src.Label), err) } // Use a pointer-field probe to detect whether top_k was explicitly // present in the JSON body. int32's zero value is indistinguishable @@ -252,20 +252,20 @@ func runSearchCmd(ctx context.Context, ic RecordService, options searchCmdOption } if req.Query.TopK <= 0 { - return pcio.Errorf("top-k must be greater than 0") + return fmt.Errorf("top-k must be greater than 0") } if req.Query.Id == nil && req.Query.Inputs == nil && req.Query.Vector == nil { - return pcio.Errorf("provide a query via --inputs, --id, --vector, --sparse-indices/--sparse-values, or a --body") + return fmt.Errorf("provide a query via --inputs, --id, --vector, --sparse-indices/--sparse-values, or a --body") } resp, err := ic.SearchRecords(ctx, &req) if err != nil { - return pcio.Errorf("failed to search records: %w", err) + return fmt.Errorf("failed to search records: %w", err) } if options.json { - pcio.PrintJSON(text.IndentJSON(resp)) + fmt.Println(text.IndentJSON(resp)) } else { presenters.PrintSearchRecordsTable(resp) } diff --git a/internal/pkg/cli/command/index/record/upsert.go b/internal/pkg/cli/command/index/record/upsert.go index 988b64d3..4fdb3577 100644 --- a/internal/pkg/cli/command/index/record/upsert.go +++ b/internal/pkg/cli/command/index/record/upsert.go @@ -4,13 +4,13 @@ import ( "bytes" "context" "encoding/json" + "fmt" "io" "github.com/pinecone-io/cli/internal/pkg/utils/argio" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -88,17 +88,17 @@ func NewUpsertCmd() *cobra.Command { func runUpsertCmd(ctx context.Context, ic RecordService, options upsertCmdOptions) error { if options.file == "" { - return pcio.Errorf("either --file or --body must be provided") + return fmt.Errorf("either --file or --body must be provided") } b, src, err := argio.ReadAll(options.file) if err != nil { - return pcio.Errorf("failed to read upsert body (%s): %w", style.Emphasis(src.Label), err) + return fmt.Errorf("failed to read upsert body (%s): %w", style.Emphasis(src.Label), err) } payload, err := parseUpsertRecordsBody(b) if err != nil { - return pcio.Errorf("failed to parse upsert body (%s): %w", style.Emphasis(src.Label), err) + return fmt.Errorf("failed to parse upsert body (%s): %w", style.Emphasis(src.Label), err) } records := make([]*pinecone.IntegratedRecord, 0, len(payload.Records)) @@ -121,7 +121,7 @@ func runUpsertCmd(ctx context.Context, ic RecordService, options upsertCmdOption for i, batch := range batches { if err := ic.UpsertRecords(ctx, batch); err != nil { - return pcio.Errorf("failed to upsert %d records in batch %d: %w", len(batch), i+1, err) + return fmt.Errorf("failed to upsert %d records in batch %d: %w", len(batch), i+1, err) } if options.json { summary := map[string]any{ @@ -130,7 +130,7 @@ func runUpsertCmd(ctx context.Context, ic RecordService, options upsertCmdOption "records": len(batch), "namespace": options.namespace, } - pcio.PrintJSON(text.IndentJSON(summary)) + fmt.Println(text.IndentJSON(summary)) } else { msg.SuccessMsg("Upserted %d records into namespace %s (batch %d of %d)", len(batch), options.namespace, i+1, len(batches)) } @@ -142,7 +142,7 @@ func runUpsertCmd(ctx context.Context, ic RecordService, options upsertCmdOption func parseUpsertRecordsBody(b []byte) (*UpsertRecordsBody, error) { trimmed := bytes.TrimSpace(b) if len(trimmed) == 0 { - return nil, pcio.Errorf("no records provided") + return nil, fmt.Errorf("no records provided") } switch trimmed[0] { @@ -153,7 +153,7 @@ func parseUpsertRecordsBody(b []byte) (*UpsertRecordsBody, error) { return nil, err } if len(records) == 0 { - return nil, pcio.Errorf("no records provided") + return nil, fmt.Errorf("no records provided") } return &UpsertRecordsBody{Records: records}, nil @@ -161,7 +161,7 @@ func parseUpsertRecordsBody(b []byte) (*UpsertRecordsBody, error) { return parseUpsertRecordsFromObjects(trimmed) default: - return nil, pcio.Errorf("input must be a JSON object, array, or JSONL") + return nil, fmt.Errorf("input must be a JSON object, array, or JSONL") } } @@ -176,7 +176,7 @@ func parseUpsertRecordsFromObjects(b []byte) (*UpsertRecordsBody, error) { dec.DisallowUnknownFields() if err := dec.Decode(&payload); err == nil { if len(payload.Records) == 0 { - return nil, pcio.Errorf("no records provided") + return nil, fmt.Errorf("no records provided") } return &payload, nil } @@ -212,7 +212,7 @@ func parseUpsertRecordsFromObjects(b []byte) (*UpsertRecordsBody, error) { records = append(records, rec) } if len(records) == 0 { - return nil, pcio.Errorf("no records provided") + return nil, fmt.Errorf("no records provided") } // A single decoded object that carries a "records"-shaped key was almost // certainly intended as the {"records":[...]} wrapper but has a typo or @@ -237,12 +237,12 @@ func rejectIfMalformedWrapper(rec pinecone.IntegratedRecord) error { // that prevented the lenient wrapper parse from matching). if v, ok := m["records"]; ok { if _, isSlice := v.([]interface{}); isSlice { - return pcio.Errorf(`found a top-level "records" array; expected wrapper format {"records":[...]}`) + return fmt.Errorf(`found a top-level "records" array; expected wrapper format {"records":[...]}`) } } // "record" (singular) is the most common key-name typo for the wrapper. if _, ok := m["record"]; ok { - return pcio.Errorf(`unknown key "record": did you mean "records"? Expected format: {"records":[...]}`) + return fmt.Errorf(`unknown key "record": did you mean "records"? Expected format: {"records":[...]}`) } return nil } diff --git a/internal/pkg/cli/command/index/vector/fetch.go b/internal/pkg/cli/command/index/vector/fetch.go index 8c385509..d721cc5f 100644 --- a/internal/pkg/cli/command/index/vector/fetch.go +++ b/internal/pkg/cli/command/index/vector/fetch.go @@ -2,13 +2,13 @@ package vector import ( "context" + "fmt" "github.com/pinecone-io/cli/internal/pkg/utils/argio" "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/flags" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -159,7 +159,7 @@ func runFetchCmd(ctx context.Context, options fetchCmdOptions) { func printFetchVectorsResults(results *presenters.FetchVectorsResults, options fetchCmdOptions) { if options.json { json := text.IndentJSON(results) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintFetchVectorsTable(results) } diff --git a/internal/pkg/cli/command/index/vector/list_vectors.go b/internal/pkg/cli/command/index/vector/list_vectors.go index ada12df2..01994445 100644 --- a/internal/pkg/cli/command/index/vector/list_vectors.go +++ b/internal/pkg/cli/command/index/vector/list_vectors.go @@ -2,11 +2,11 @@ package vector import ( "context" + "fmt" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -76,7 +76,7 @@ func runListVectorsCmd(ctx context.Context, options listVectorsCmdOptions) { if options.json { json := text.IndentJSON(resp) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintListVectorsTable(resp) } diff --git a/internal/pkg/cli/command/index/vector/query.go b/internal/pkg/cli/command/index/vector/query.go index c5acc69c..673b1618 100644 --- a/internal/pkg/cli/command/index/vector/query.go +++ b/internal/pkg/cli/command/index/vector/query.go @@ -2,13 +2,13 @@ package vector import ( "context" + "fmt" "github.com/pinecone-io/cli/internal/pkg/utils/argio" "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/flags" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -208,7 +208,7 @@ func runQueryCmd(ctx context.Context, options queryCmdOptions) { if options.json { json := text.IndentJSON(queryResponse) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintQueryVectorsTable(queryResponse) } diff --git a/internal/pkg/cli/command/index/vector/update.go b/internal/pkg/cli/command/index/vector/update.go index ccf8a566..04dd2b04 100644 --- a/internal/pkg/cli/command/index/vector/update.go +++ b/internal/pkg/cli/command/index/vector/update.go @@ -2,13 +2,13 @@ package vector import ( "context" + "fmt" "github.com/pinecone-io/cli/internal/pkg/utils/argio" "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/flags" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -197,7 +197,7 @@ func runUpdateCmd(ctx context.Context, options updateCmdOptions) { presenters.PrintUpdateVectorsByMetadataTable(resp) } else { json := text.IndentJSON(resp) - pcio.PrintJSON(json) + fmt.Println(json) } return } diff --git a/internal/pkg/cli/command/index/vector/upsert.go b/internal/pkg/cli/command/index/vector/upsert.go index 10093f57..af4c0d26 100644 --- a/internal/pkg/cli/command/index/vector/upsert.go +++ b/internal/pkg/cli/command/index/vector/upsert.go @@ -4,13 +4,13 @@ import ( "bytes" "context" "encoding/json" + "fmt" "io" "github.com/pinecone-io/cli/internal/pkg/utils/argio" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -136,7 +136,7 @@ func runUpsertCmd(ctx context.Context, options upsertCmdOptions) { } else { if options.json { json := text.IndentJSON(resp) - pcio.PrintJSON(json) + fmt.Println(json) } else { msg.SuccessMsg("Upserted %d vectors into namespace %s (batch %d of %d)", len(batch), options.namespace, i+1, len(batches)) } @@ -152,7 +152,7 @@ func parseUpsertBody(b []byte) (*UpsertBody, error) { dec.DisallowUnknownFields() if err := dec.Decode(&payload); err == nil { if len(payload.Vectors) == 0 { - return nil, pcio.Errorf("no vectors provided") + return nil, fmt.Errorf("no vectors provided") } return &payload, nil } @@ -165,7 +165,7 @@ func parseUpsertBody(b []byte) (*UpsertBody, error) { dec.DisallowUnknownFields() if err := dec.Decode(&vectors); err == nil { if len(vectors) == 0 { - return nil, pcio.Errorf("no vectors provided") + return nil, fmt.Errorf("no vectors provided") } return &UpsertBody{Vectors: vectors}, nil } @@ -185,7 +185,7 @@ func parseUpsertBody(b []byte) (*UpsertBody, error) { vectors = append(vectors, v) } if len(vectors) == 0 { - return nil, pcio.Errorf("no vectors provided") + return nil, fmt.Errorf("no vectors provided") } return &UpsertBody{Vectors: vectors}, nil } diff --git a/internal/pkg/cli/command/organization/delete.go b/internal/pkg/cli/command/organization/delete.go index 37e72827..7c9d2e53 100644 --- a/internal/pkg/cli/command/organization/delete.go +++ b/internal/pkg/cli/command/organization/delete.go @@ -11,7 +11,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -104,13 +103,13 @@ func confirmDelete(organizationName string, organizationID string) { msg.WarnMsg("This action cannot be undone.") // Prompt the user - pcio.Print("Do you want to continue? (y/N): ") + fmt.Print("Do you want to continue? (y/N): ") // Read the user's input reader := bufio.NewReader(os.Stdin) input, err := reader.ReadString('\n') if err != nil { - pcio.Println(fmt.Errorf("Error reading input: %w", err)) + fmt.Println(fmt.Errorf("Error reading input: %w", err)) return } diff --git a/internal/pkg/cli/command/organization/delete_test.go b/internal/pkg/cli/command/organization/delete_test.go index 56ad78fc..7d63d34d 100644 --- a/internal/pkg/cli/command/organization/delete_test.go +++ b/internal/pkg/cli/command/organization/delete_test.go @@ -3,7 +3,6 @@ package organization import ( "context" "errors" - "os" "testing" "github.com/pinecone-io/cli/internal/pkg/cli/testutils" @@ -20,13 +19,6 @@ func (m *mockDeleteOrganizationService) Delete(ctx context.Context, id string) e return m.deleteErr } -func TestMain(m *testing.M) { - reset := testutils.SilenceOutput() - code := m.Run() - reset() - os.Exit(code) -} - func Test_runDeleteOrganizationCmd_Succeeds(t *testing.T) { svc := &mockDeleteOrganizationService{} opts := deleteOrganizationCmdOptions{organizationID: "org-123"} diff --git a/internal/pkg/cli/command/organization/describe.go b/internal/pkg/cli/command/organization/describe.go index 102b03e9..cbc0b6e3 100644 --- a/internal/pkg/cli/command/organization/describe.go +++ b/internal/pkg/cli/command/organization/describe.go @@ -1,11 +1,12 @@ package organization import ( + "fmt" + "github.com/pinecone-io/cli/internal/pkg/utils/configuration/state" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -50,7 +51,7 @@ func NewDescribeOrganizationCmd() *cobra.Command { if options.json { json := text.IndentJSON(org) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintDescribeOrganizationTable(org) } diff --git a/internal/pkg/cli/command/organization/list.go b/internal/pkg/cli/command/organization/list.go index 823f73fa..93ed1689 100644 --- a/internal/pkg/cli/command/organization/list.go +++ b/internal/pkg/cli/command/organization/list.go @@ -1,6 +1,7 @@ package organization import ( + "fmt" "strings" "github.com/spf13/cobra" @@ -8,7 +9,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -41,7 +41,7 @@ func NewListOrganizationsCmd() *cobra.Command { if options.json { json := text.IndentJSON(orgs) - pcio.PrintJSON(json) + fmt.Println(json) return } @@ -59,7 +59,7 @@ func printTable(orgs []*pinecone.Organization) { columns := []string{"NAME", "ID", "CREATED AT", "PAYMENT STATUS", "PLAN", "SUPPORT TIER"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, org := range orgs { values := []string{ @@ -70,7 +70,7 @@ func printTable(orgs []*pinecone.Organization) { org.Plan, org.SupportTier, } - pcio.Fprintf(writer, strings.Join(values, "\t")+"\n") + fmt.Fprintf(writer, strings.Join(values, "\t")+"\n") } writer.Flush() } diff --git a/internal/pkg/cli/command/organization/update.go b/internal/pkg/cli/command/organization/update.go index c24cd8e2..b7749946 100644 --- a/internal/pkg/cli/command/organization/update.go +++ b/internal/pkg/cli/command/organization/update.go @@ -1,11 +1,12 @@ package organization import ( + "fmt" + "github.com/pinecone-io/cli/internal/pkg/utils/configuration/state" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -58,7 +59,7 @@ func NewUpdateOrganizationCmd() *cobra.Command { if options.json { json := text.IndentJSON(org) - pcio.PrintJSON(json) + fmt.Println(json) return } diff --git a/internal/pkg/cli/command/project/create.go b/internal/pkg/cli/command/project/create.go index 1732077d..e0c01256 100644 --- a/internal/pkg/cli/command/project/create.go +++ b/internal/pkg/cli/command/project/create.go @@ -1,11 +1,12 @@ package project import ( + "fmt" + "github.com/pinecone-io/cli/internal/pkg/utils/configuration/state" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -69,7 +70,7 @@ func NewCreateProjectCmd() *cobra.Command { if options.json { json := text.IndentJSON(proj) - pcio.PrintJSON(json) + fmt.Println(json) return } diff --git a/internal/pkg/cli/command/project/delete.go b/internal/pkg/cli/command/project/delete.go index 58ba0d6e..c14a5de7 100644 --- a/internal/pkg/cli/command/project/delete.go +++ b/internal/pkg/cli/command/project/delete.go @@ -11,7 +11,6 @@ import ( "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" @@ -117,13 +116,13 @@ func confirmDelete(projectName string) { msg.WarnMsg("This action cannot be undone.") // Prompt the user - pcio.Print("Do you want to continue? (y/N): ") + fmt.Print("Do you want to continue? (y/N): ") // Read the user's input reader := bufio.NewReader(os.Stdin) input, err := reader.ReadString('\n') if err != nil { - pcio.Println(fmt.Errorf("Error reading input: %w", err)) + fmt.Println(fmt.Errorf("Error reading input: %w", err)) return } @@ -150,7 +149,7 @@ func verifyNoIndexes(ctx context.Context, projectId string, projectName string) } if len(idxs) > 0 { msg.FailMsg("Project %s contains indexes. Delete the indexes before deleting the project.", style.Emphasis(projectName)) - msg.HintMsg("To see indexes in this project, run %s", pcio.Sprintf(style.Code("pc target -p \"%s\" && pc index list"), projectName)) + msg.HintMsg("To see indexes in this project, run %s", fmt.Sprintf(style.Code("pc target -p \"%s\" && pc index list"), projectName)) exit.ErrorMsgf("Project %s contains indexes. Delete the indexes before deleting the project.", style.Emphasis(projectName)) } } @@ -166,7 +165,7 @@ func verifyNoCollections(ctx context.Context, projectId string, projectName stri } if len(collections) > 0 { msg.FailMsg("Project %s contains collections. Delete the collections before deleting the project.", style.Emphasis(projectName)) - msg.HintMsg("To see collections in this project, run %s", pcio.Sprintf(style.Code("pc target -p \"%s\" && pc collection list"), projectName)) + msg.HintMsg("To see collections in this project, run %s", fmt.Sprintf(style.Code("pc target -p \"%s\" && pc collection list"), projectName)) exit.ErrorMsgf("Project %s contains collections. Delete the collections before deleting the project.", style.Emphasis(projectName)) } } diff --git a/internal/pkg/cli/command/project/delete_test.go b/internal/pkg/cli/command/project/delete_test.go index e707adb6..3dabd8e0 100644 --- a/internal/pkg/cli/command/project/delete_test.go +++ b/internal/pkg/cli/command/project/delete_test.go @@ -3,7 +3,6 @@ package project import ( "context" "errors" - "os" "testing" "github.com/pinecone-io/cli/internal/pkg/cli/testutils" @@ -20,13 +19,6 @@ func (m *mockDeleteProjectService) Delete(ctx context.Context, id string) error return m.deleteErr } -func TestMain(m *testing.M) { - reset := testutils.SilenceOutput() - code := m.Run() - reset() - os.Exit(code) -} - func Test_runDeleteProjectCmd_Succeeds(t *testing.T) { svc := &mockDeleteProjectService{} opts := deleteProjectCmdOptions{projectId: "proj-123"} diff --git a/internal/pkg/cli/command/project/describe.go b/internal/pkg/cli/command/project/describe.go index bbc6778f..ea7c8178 100644 --- a/internal/pkg/cli/command/project/describe.go +++ b/internal/pkg/cli/command/project/describe.go @@ -1,11 +1,12 @@ package project import ( + "fmt" + "github.com/pinecone-io/cli/internal/pkg/utils/configuration/state" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -50,7 +51,7 @@ func NewDescribeProjectCmd() *cobra.Command { if options.json { json := text.IndentJSON(project) - pcio.PrintJSON(json) + fmt.Println(json) } else { presenters.PrintDescribeProjectTable(project) } diff --git a/internal/pkg/cli/command/project/list.go b/internal/pkg/cli/command/project/list.go index 987af1d7..e8f382da 100644 --- a/internal/pkg/cli/command/project/list.go +++ b/internal/pkg/cli/command/project/list.go @@ -1,6 +1,7 @@ package project import ( + "fmt" "strconv" "strings" @@ -12,8 +13,6 @@ import ( "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/pinecone-io/go-pinecone/v5/pinecone" "github.com/spf13/cobra" - - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" ) type listProjectCmdOptions struct { @@ -42,7 +41,7 @@ func NewListProjectsCmd() *cobra.Command { if options.json { json := text.IndentJSON(projects) - pcio.PrintJSON(json) + fmt.Println(json) } else { printTable(projects) } @@ -59,7 +58,7 @@ func printTable(projects []*pinecone.Project) { columns := []string{"NAME", "ID", "ORGANIZATION ID", "CREATED AT", "FORCE ENCRYPTION", "MAX PODS"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, proj := range projects { values := []string{ @@ -69,7 +68,7 @@ func printTable(projects []*pinecone.Project) { proj.CreatedAt.String(), strconv.FormatBool(proj.ForceEncryptionWithCmek), strconv.Itoa(proj.MaxPods)} - pcio.Fprintf(writer, strings.Join(values, "\t")+"\n") + fmt.Fprintf(writer, strings.Join(values, "\t")+"\n") } writer.Flush() } diff --git a/internal/pkg/cli/command/project/update.go b/internal/pkg/cli/command/project/update.go index ec29f085..1a56c3a7 100644 --- a/internal/pkg/cli/command/project/update.go +++ b/internal/pkg/cli/command/project/update.go @@ -1,11 +1,12 @@ package project import ( + "fmt" + "github.com/pinecone-io/cli/internal/pkg/utils/configuration/state" "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/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" @@ -67,7 +68,7 @@ func NewUpdateProjectCmd() *cobra.Command { if options.json { json := text.IndentJSON(project) - pcio.PrintJSON(json) + fmt.Println(json) return } diff --git a/internal/pkg/cli/command/root/root.go b/internal/pkg/cli/command/root/root.go index 6a9ff4de..dc2c848b 100644 --- a/internal/pkg/cli/command/root/root.go +++ b/internal/pkg/cli/command/root/root.go @@ -21,7 +21,6 @@ import ( "github.com/pinecone-io/cli/internal/pkg/cli/command/version" "github.com/pinecone-io/cli/internal/pkg/cli/command/whoami" "github.com/pinecone-io/cli/internal/pkg/utils/help" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/spf13/cobra" ) @@ -32,7 +31,6 @@ var ( ) type GlobalOptions struct { - quiet bool timeout time.Duration } @@ -85,8 +83,6 @@ func init() { Use: "pc", Short: "Manage your Pinecone vector database infrastructure from the command line", PersistentPreRun: func(cmd *cobra.Command, args []string) { - pcio.SetQuiet(globalOptions.quiet) - // Apply timeout to the command context if globalOptions.timeout > 0 { ctx, cancel := context.WithTimeout(cmd.Context(), globalOptions.timeout) @@ -144,6 +140,5 @@ func init() { }) // Global flags - rootCmd.PersistentFlags().BoolVarP(&globalOptions.quiet, "quiet", "q", false, "suppress output") rootCmd.PersistentFlags().DurationVar(&globalOptions.timeout, "timeout", defaultTimeout, "timeout for commands, defaults to 60s (0 to disable)") } diff --git a/internal/pkg/cli/command/target/target.go b/internal/pkg/cli/command/target/target.go index c2e57335..6c7f1335 100644 --- a/internal/pkg/cli/command/target/target.go +++ b/internal/pkg/cli/command/target/target.go @@ -1,6 +1,7 @@ package target import ( + "fmt" "os" "strings" @@ -14,7 +15,6 @@ import ( "github.com/pinecone-io/cli/internal/pkg/utils/login" "github.com/pinecone-io/cli/internal/pkg/utils/msg" "github.com/pinecone-io/cli/internal/pkg/utils/oauth" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/presenters" "github.com/pinecone-io/cli/internal/pkg/utils/prompt" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" @@ -101,7 +101,7 @@ func NewTargetCmd() *cobra.Command { defaultAPIKey := secrets.DefaultAPIKey.Get() targetContext.DefaultAPIKey = presenters.MaskHeadTail(defaultAPIKey, 4, 4) json := text.IndentJSON(targetContext) - pcio.PrintJSON(json) + fmt.Println(json) return } log.Info(). @@ -152,8 +152,8 @@ func NewTargetCmd() *cobra.Command { msg.FailMsg("Failed to target an organization") exit.ErrorMsg("Failed to target an organization") } else { - pcio.Println() - pcio.Printf(style.SuccessMsg("Target org set to %s.\n"), style.Emphasis(targetOrg.Name)) + fmt.Println() + fmt.Printf(style.SuccessMsg("Target org set to %s.\n"), style.Emphasis(targetOrg.Name)) // If the org chosen differs from the current orgId in the token, we need to login again if currentTokenOrgId != "" && currentTokenOrgId != targetOrg.Id { @@ -180,7 +180,7 @@ func NewTargetCmd() *cobra.Command { msg.FailMsg("Failed to target a project") exit.ErrorMsg("failed to target a project") } else { - pcio.Printf(style.SuccessMsg("Target project set %s.\n"), style.Emphasis(targetProject.Name)) + fmt.Printf(style.SuccessMsg("Target project set %s.\n"), style.Emphasis(targetProject.Name)) return } } @@ -260,11 +260,11 @@ func NewTargetCmd() *cobra.Command { defaultAPIKey := secrets.DefaultAPIKey.Get() targetContext.DefaultAPIKey = presenters.MaskHeadTail(defaultAPIKey, 4, 4) json := text.IndentJSON(targetContext) - pcio.PrintJSON(json) + fmt.Println(json) return } - pcio.Println() + fmt.Println() presenters.PrintTargetContext(state.GetTargetContext()) }, @@ -285,12 +285,12 @@ func NewTargetCmd() *cobra.Command { func validateTargetOptions(options targetCmdOptions) error { // Check organization targeting if options.org != "" && options.orgID != "" { - return pcio.Errorf("cannot specify both --org and --organization-id, use one or the other") + return fmt.Errorf("cannot specify both --org and --organization-id, use one or the other") } // Check project targeting if options.project != "" && options.projectID != "" { - return pcio.Errorf("cannot specify both --project and --project-id, use one or the other") + return fmt.Errorf("cannot specify both --project and --project-id, use one or the other") } return nil @@ -330,7 +330,7 @@ func getOrgForTarget(orgs []*pinecone.Organization, orgName, orgID string) (*pin orgNames[i] = org.Name } availableOrgs := strings.Join(orgNames, ", ") - return nil, pcio.Errorf("organization %s: %s not found. Available organizations: %s", + return nil, fmt.Errorf("organization %s: %s not found. Available organizations: %s", style.Emphasis(searchType), style.Emphasis(searchValue), availableOrgs) @@ -373,7 +373,7 @@ func getProjectForTarget(projects []*pinecone.Project, projectName, projectID st projectNames[i] = project.Name } availableProjects := strings.Join(projectNames, ", ") - return nil, pcio.Errorf("project %s: %s not found. Available projects: %s", + return nil, fmt.Errorf("project %s: %s not found. Available projects: %s", style.Emphasis(searchType), style.Emphasis(searchValue), availableProjects) @@ -395,8 +395,8 @@ func postLoginInteractiveTargetOrg(orgsList []*pinecone.Organization) *pinecone. orgName = organization.Name log.Info().Msgf("Only 1 organization present. Target organization set to %s", orgName) } else { - pcio.Println("Many API operations take place in the context of a specific org and project.") - pcio.Println(pcio.Sprintf("This CLI maintains a piece of state called the %s so it knows which \n", style.Emphasis("target")) + + fmt.Println("Many API operations take place in the context of a specific org and project.") + fmt.Println(fmt.Sprintf("This CLI maintains a piece of state called the %s so it knows which \n", style.Emphasis("target")) + "organization and project to use when calling the API on your behalf.") orgNames := []string{} @@ -457,15 +457,15 @@ func postLoginInteractiveTargetProject(projectList []*pinecone.Project) *pinecon func uiProjectSelector(projectItems []string) string { var targetProject string = "" m2 := prompt.NewList(projectItems, len(projectItems)+6, "Choose a project to target", func() { - pcio.Println("Exiting without targeting a project.") - pcio.Printf("You can always run %s to set or change a project context later.\n", style.Code("pc target")) + fmt.Println("Exiting without targeting a project.") + fmt.Printf("You can always run %s to set or change a project context later.\n", style.Code("pc target")) exit.Success() }, func(choice string) string { targetProject = choice return "Target project: " + choice }) if _, err := tea.NewProgram(m2).Run(); err != nil { - pcio.Println("Error running program:", err) + fmt.Println("Error running program:", err) os.Exit(1) } return targetProject @@ -474,15 +474,15 @@ func uiProjectSelector(projectItems []string) string { func uiOrgSelector(orgNames []string) string { var orgName string m := prompt.NewList(orgNames, len(orgNames)+6, "Choose an organization to target", func() { - pcio.Println("Exiting without targeting an organization.") - pcio.Printf("You can always run %s to set or change a project context later.\n", style.Code("pc target")) + fmt.Println("Exiting without targeting an organization.") + fmt.Printf("You can always run %s to set or change a project context later.\n", style.Code("pc target")) exit.Success() }, func(choice string) string { orgName = choice return "Target organization: " + choice }) if _, err := tea.NewProgram(m).Run(); err != nil { - pcio.Println("Error running program:", err) + fmt.Println("Error running program:", err) os.Exit(1) } return orgName diff --git a/internal/pkg/cli/testutils/test_utils.go b/internal/pkg/cli/testutils/test_utils.go index b4e98fa5..6f7f663f 100644 --- a/internal/pkg/cli/testutils/test_utils.go +++ b/internal/pkg/cli/testutils/test_utils.go @@ -6,16 +6,8 @@ import ( "os" "strings" "testing" - - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" ) -// Silences pcio output for tests and, and returns a function to restore it -func SilenceOutput() func() { - pcio.SetQuiet(true) - return func() { pcio.SetQuiet(false) } -} - // CaptureStdout redirects os.Stdout to a pipe for the duration of f, // returning everything written to stdout as a trimmed string. func CaptureStdout(t *testing.T, f func()) string { diff --git a/internal/pkg/utils/configuration/files.go b/internal/pkg/utils/configuration/files.go index fc1442a4..ef947a48 100644 --- a/internal/pkg/utils/configuration/files.go +++ b/internal/pkg/utils/configuration/files.go @@ -9,7 +9,6 @@ import ( "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/spf13/viper" ) @@ -46,7 +45,7 @@ func (c ConfigFile) Clear() { log.Debug().Str("file_name", c.FileName).Msg("Clearing config file") for _, property := range c.Properties { log.Debug(). - Str("property", pcio.Sprintf("%s", reflect.TypeOf(property))). + Str("property", fmt.Sprintf("%s", reflect.TypeOf(property))). Msg("Clearing property") property.Clear() } diff --git a/internal/pkg/utils/configuration/state/context.go b/internal/pkg/utils/configuration/state/context.go index 134c090a..a0491d57 100644 --- a/internal/pkg/utils/configuration/state/context.go +++ b/internal/pkg/utils/configuration/state/context.go @@ -1,8 +1,6 @@ package state -import ( - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" -) +import "fmt" type TargetOrganization struct { Name string `json:"name"` @@ -46,7 +44,7 @@ func GetTargetContext() *TargetContext { func GetTargetOrgId() (string, error) { orgId := TargetOrg.Get().Id if orgId == "" { - return "", pcio.Errorf("no target organization set") + return "", fmt.Errorf("no target organization set") } return orgId, nil } @@ -54,7 +52,7 @@ func GetTargetOrgId() (string, error) { func GetTargetProjectId() (string, error) { projId := TargetProj.Get().Id if projId == "" { - return "", pcio.Errorf("no target project set") + return "", fmt.Errorf("no target project set") } return projId, nil } @@ -62,7 +60,7 @@ func GetTargetProjectId() (string, error) { func GetTargetUserAuthContext() (string, error) { context := AuthedUser.Get() if context.AuthContext == AuthNone { - return "", pcio.Errorf("no target authentication context set") + return "", fmt.Errorf("no target authentication context set") } return string(context.AuthContext), nil } diff --git a/internal/pkg/utils/flags/flags.go b/internal/pkg/utils/flags/flags.go index 843e4044..15858848 100644 --- a/internal/pkg/utils/flags/flags.go +++ b/internal/pkg/utils/flags/flags.go @@ -2,10 +2,10 @@ package flags import ( "encoding/json" + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/argio" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" ) type JSONObject map[string]any @@ -29,7 +29,7 @@ func (m *JSONObject) Set(value string) error { var tmp map[string]any if err := json.NewDecoder(rc).Decode(&tmp); err != nil { - return pcio.Errorf("failed to parse JSON: %w", err) + return fmt.Errorf("failed to parse JSON: %w", err) } *m = tmp return nil @@ -60,7 +60,7 @@ func (m *Float32List) Set(value string) error { var arr []float32 if err := json.NewDecoder(rc).Decode(&arr); err != nil { - return pcio.Errorf("failed to parse JSON float32 array: %w", err) + return fmt.Errorf("failed to parse JSON float32 array: %w", err) } *m = append((*m)[:0], arr...) return nil @@ -91,7 +91,7 @@ func (m *UInt32List) Set(value string) error { var arr []uint32 if err := json.NewDecoder(rc).Decode(&arr); err != nil { - return pcio.Errorf("failed to parse JSON uint32 array: %w", err) + return fmt.Errorf("failed to parse JSON uint32 array: %w", err) } *m = append((*m)[:0], arr...) return nil @@ -122,7 +122,7 @@ func (m *Int32List) Set(value string) error { var arr []int32 if err := json.NewDecoder(rc).Decode(&arr); err != nil { - return pcio.Errorf("failed to parse JSON int32 array: %w", err) + return fmt.Errorf("failed to parse JSON int32 array: %w", err) } *m = append((*m)[:0], arr...) return nil @@ -153,7 +153,7 @@ func (m *StringList) Set(value string) error { var arr []string if err := json.NewDecoder(rc).Decode(&arr); err != nil { - return pcio.Errorf("failed to parse JSON string array: %w", err) + return fmt.Errorf("failed to parse JSON string array: %w", err) } *m = append((*m)[:0], arr...) return nil diff --git a/internal/pkg/utils/login/login.go b/internal/pkg/utils/login/login.go index c1e6d534..73d91c6f 100644 --- a/internal/pkg/utils/login/login.go +++ b/internal/pkg/utils/login/login.go @@ -7,6 +7,7 @@ import ( _ "embed" "encoding/base64" "errors" + "fmt" "html/template" "io" "net/http" @@ -20,7 +21,6 @@ import ( "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/oauth" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/sdk" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/go-pinecone/v5/pinecone" @@ -111,13 +111,13 @@ func Run(ctx context.Context, io IO, opts Options) { Name: targetOrg.Name, Id: targetOrg.Id, }) - pcio.Println() - pcio.Printf(style.InfoMsg("Target org set to %s.\n"), style.Emphasis(targetOrg.Name)) + fmt.Println() + fmt.Printf(style.InfoMsg("Target org set to %s.\n"), style.Emphasis(targetOrg.Name)) if projects != nil { if len(projects) == 0 { - pcio.Printf(style.InfoMsg("No projects found for organization %s.\n"), style.Emphasis(targetOrg.Name)) - pcio.Println(style.InfoMsg("Please create a project for this organization to work with project resources.")) + fmt.Printf(style.InfoMsg("No projects found for organization %s.\n"), style.Emphasis(targetOrg.Name)) + fmt.Println(style.InfoMsg("Please create a project for this organization to work with project resources.")) } else { targetProj := projects[0] state.TargetProj.Set(state.TargetProject{ @@ -125,15 +125,15 @@ func Run(ctx context.Context, io IO, opts Options) { Id: targetProj.Id, }) - pcio.Printf(style.InfoMsg("Target project set %s.\n"), style.Emphasis(targetProj.Name)) + fmt.Printf(style.InfoMsg("Target project set %s.\n"), style.Emphasis(targetProj.Name)) } } - pcio.Println() - pcio.Println(style.CodeHint("Run %s to change the target context.", style.Code("pc target"))) + fmt.Println() + fmt.Println(style.CodeHint("Run %s to change the target context.", style.Code("pc target"))) - pcio.Println() - pcio.Printf("Now try %s to learn about index operations.\n", style.Code("pc index -h")) + fmt.Println() + fmt.Printf("Now try %s to learn about index operations.\n", style.Code("pc index -h")) } // Takes an optional orgId, and attempts to acquire an access token scoped to the orgId if provided. @@ -147,12 +147,12 @@ func GetAndSetAccessToken(ctx context.Context, orgId *string) error { // PKCE verifier and challenge verifier, challenge, err := a.CreateNewVerifierAndChallenge() if err != nil { - return pcio.Errorf("error creating new auth verifier and challenge: %w", err) + return fmt.Errorf("error creating new auth verifier and challenge: %w", err) } authURL, err := a.GetAuthURL(ctx, csrfState, challenge, orgId) if err != nil { - return pcio.Errorf("error getting auth URL: %w", err) + return fmt.Errorf("error getting auth URL: %w", err) } // Spin up a local server in a goroutine to handle receiving the authorization code from auth0 @@ -170,9 +170,9 @@ func GetAndSetAccessToken(ctx context.Context, orgId *string) error { codeCh <- code }() - pcio.Printf("Visit %s to authorize the CLI.\n", style.Underline(authURL)) - pcio.Println() - pcio.Printf("Press %s to open the browser, or manually paste the URL above.\n", style.Code("[Enter]")) + fmt.Printf("Visit %s to authorize the CLI.\n", style.Underline(authURL)) + fmt.Println() + fmt.Printf("Press %s to open the browser, or manually paste the URL above.\n", style.Code("[Enter]")) // spawn a goroutine to optionally wait for [Enter] as input go func(ctx context.Context) { @@ -208,12 +208,12 @@ func GetAndSetAccessToken(ctx context.Context, orgId *string) error { // Wait for auth code and exchange for access token code := <-codeCh if code == "" { - return pcio.Error("error authenticating CLI and retrieving oauth2 access token") + return errors.New("error authenticating CLI and retrieving oauth2 access token") } token, err := a.ExchangeAuthCode(ctx, verifier, code) if err != nil { - return pcio.Errorf("error exchanging auth code for access token: %w", err) + return fmt.Errorf("error exchanging auth code for access token: %w", err) } claims, err := oauth.ParseClaimsUnverified(token) @@ -257,7 +257,7 @@ func ServeAuthCodeListener(ctx context.Context, csrfState string) (string, error state := r.URL.Query().Get("state") if state != csrfState { - errCh <- pcio.Errorf("state mismatch on authentication") + errCh <- fmt.Errorf("state mismatch on authentication") return } @@ -265,12 +265,12 @@ func ServeAuthCodeListener(ctx context.Context, csrfState string) (string, error templateData := map[string]template.HTML{"LogoSVG": template.HTML(logoSVG)} if code == "" { if err := renderHTML(w, errorHTML, templateData); err != nil { - errCh <- pcio.Errorf("error rendering authentication response HTML: %w", err) + errCh <- fmt.Errorf("error rendering authentication response HTML: %w", err) return } } else { if err := renderHTML(w, successHTML, templateData); err != nil { - errCh <- pcio.Errorf("error rendering authentication response HTML: %w", err) + errCh <- fmt.Errorf("error rendering authentication response HTML: %w", err) return } } @@ -285,7 +285,7 @@ func ServeAuthCodeListener(ctx context.Context, csrfState string) (string, error } go func() { if err := serve.ListenAndServe(); err != nil && err != http.ErrServerClosed { - errCh <- pcio.Errorf("error listening for auth code: %w", err) + errCh <- fmt.Errorf("error listening for auth code: %w", err) return } }() @@ -300,22 +300,22 @@ func ServeAuthCodeListener(ctx context.Context, csrfState string) (string, error case <-ctx.Done(): _ = serve.Shutdown(ctx) if ctx.Err() != nil { - return "", pcio.Errorf("error waiting for authorization: %w", ctx.Err()) + return "", fmt.Errorf("error waiting for authorization: %w", ctx.Err()) } } - return "", pcio.Error("error waiting for authentication response") + return "", errors.New("error waiting for authentication response") } func renderHTML(w http.ResponseWriter, htmlTemplate string, data map[string]template.HTML) error { tmpl, err := template.New("auth-response").Parse(htmlTemplate) if err != nil { - return pcio.Errorf("error parsing auth response HTML template: %w", err) + return fmt.Errorf("error parsing auth response HTML template: %w", err) } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) if err := tmpl.Execute(w, data); err != nil { - return pcio.Errorf("error executing auth response HTML template: %w", err) + return fmt.Errorf("error executing auth response HTML template: %w", err) } return nil } diff --git a/internal/pkg/utils/oauth/token.go b/internal/pkg/utils/oauth/token.go index 047c9c8d..f9518140 100644 --- a/internal/pkg/utils/oauth/token.go +++ b/internal/pkg/utils/oauth/token.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "net/http" "net/url" "strings" @@ -11,7 +12,6 @@ import ( "time" "github.com/pinecone-io/cli/internal/pkg/utils/configuration/secrets" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "golang.org/x/oauth2" ) @@ -182,7 +182,7 @@ func refreshTokenWithOrg(ctx context.Context, cfg *oauth2.Config, currToken *oau return nil, err } if tokenResp.AccessToken == "" { - return nil, pcio.Errorf("failed to refresh user token: no access token returned") + return nil, fmt.Errorf("failed to refresh user token: no access token returned") } // Return a standard oauth2.Token diff --git a/internal/pkg/utils/pcio/io.go b/internal/pkg/utils/pcio/io.go deleted file mode 100644 index 34c018b9..00000000 --- a/internal/pkg/utils/pcio/io.go +++ /dev/null @@ -1,7 +0,0 @@ -package pcio - -import ( - "github.com/spf13/cobra" -) - -var Messages = (&cobra.Command{}).OutOrStdout() diff --git a/internal/pkg/utils/pcio/print.go b/internal/pkg/utils/pcio/print.go deleted file mode 100644 index 33b59182..00000000 --- a/internal/pkg/utils/pcio/print.go +++ /dev/null @@ -1,81 +0,0 @@ -package pcio - -import ( - "fmt" - "io" - "os" -) - -// The purpose of this package is to stub out the fmt package so that -// the -q quiet mode can be implemented in a consistent way across all -// commands. - -var quiet bool - -func SetQuiet(q bool) { - quiet = q -} - -// PrintJSON writes s to stdout regardless of quiet mode. -// Use this instead of Println when outputting structured JSON so that -// --quiet does not suppress machine-readable output. -func PrintJSON(s string) { - fmt.Fprintln(os.Stdout, s) -} - -func Println(a ...any) { - if !quiet { - fmt.Println(a...) - return - } -} - -func Print(a any) { - if !quiet { - fmt.Print(a) - return - } -} - -func Printf(format string, a ...any) { - if !quiet { - fmt.Printf(format, a...) - return - } -} - -func Fprintf(w io.Writer, format string, a ...any) { - if !quiet { - fmt.Fprintf(w, format, a...) - return - } -} - -func Fprintln(w io.Writer, a ...any) { - if !quiet { - fmt.Fprintln(w, a...) - return - } -} - -func Fprint(w io.Writer, a ...any) { - if !quiet { - fmt.Fprint(w, a...) - return - } -} - -// alias Sprintf to fmt.Sprintf -func Sprintf(format string, a ...any) string { - return fmt.Sprintf(format, a...) -} - -// alias Errorf to fmt.Errorf -func Errorf(format string, a ...any) error { - return fmt.Errorf(format, a...) -} - -// alias Error to fmt.Errorf -func Error(a ...any) error { - return fmt.Errorf(fmt.Sprint(a...)) -} diff --git a/internal/pkg/utils/pcio/print_test.go b/internal/pkg/utils/pcio/print_test.go deleted file mode 100644 index 2ea06140..00000000 --- a/internal/pkg/utils/pcio/print_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package pcio - -import ( - "bytes" - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -func captureStdout(t *testing.T, fn func()) string { - t.Helper() - r, w, err := os.Pipe() - if err != nil { - t.Fatal(err) - } - orig := os.Stdout - os.Stdout = w - - fn() - - w.Close() - os.Stdout = orig - - done := make(chan string) - go func() { - var b bytes.Buffer - b.ReadFrom(r) - done <- b.String() - }() - return <-done -} - -func TestPrintJSON_EmitsWhenQuiet(t *testing.T) { - SetQuiet(true) - defer SetQuiet(false) - - out := captureStdout(t, func() { - PrintJSON("{}") - }) - - assert.Equal(t, "{}\n", out) -} - -func TestPrintJSON_EmitsWhenNotQuiet(t *testing.T) { - SetQuiet(false) - - out := captureStdout(t, func() { - PrintJSON("{}") - }) - - assert.Equal(t, "{}\n", out) -} - -func TestPrintln_SuppressedWhenQuiet(t *testing.T) { - SetQuiet(true) - defer SetQuiet(false) - - out := captureStdout(t, func() { - Println("should not appear") - }) - - assert.Empty(t, out) -} diff --git a/internal/pkg/utils/presenters/api_key_description.go b/internal/pkg/utils/presenters/api_key_description.go index 31cba647..86df4157 100644 --- a/internal/pkg/utils/presenters/api_key_description.go +++ b/internal/pkg/utils/presenters/api_key_description.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -19,12 +19,12 @@ func PrintDescribeAPIKeyTable(apiKey *pinecone.APIKey) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Name\t%s\n", apiKey.Name) - pcio.Fprintf(writer, "ID\t%s\n", apiKey.Id) - pcio.Fprintf(writer, "Project ID\t%s\n", apiKey.ProjectId) - pcio.Fprintf(writer, "Roles\t%s\n", strings.Join(apiKey.Roles, ", ")) + fmt.Fprintf(writer, "Name\t%s\n", apiKey.Name) + fmt.Fprintf(writer, "ID\t%s\n", apiKey.Id) + fmt.Fprintf(writer, "Project ID\t%s\n", apiKey.ProjectId) + fmt.Fprintf(writer, "Roles\t%s\n", strings.Join(apiKey.Roles, ", ")) writer.Flush() } diff --git a/internal/pkg/utils/presenters/api_key_with_secret.go b/internal/pkg/utils/presenters/api_key_with_secret.go index 9efa0743..ae3a8d0c 100644 --- a/internal/pkg/utils/presenters/api_key_with_secret.go +++ b/internal/pkg/utils/presenters/api_key_with_secret.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -19,13 +19,13 @@ func PrintDescribeAPIKeyWithSecretTable(apiKey *pinecone.APIKeyWithSecret) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Name\t%s\n", apiKey.Key.Name) - pcio.Fprintf(writer, "ID\t%s\n", apiKey.Key.Id) - pcio.Fprintf(writer, "Value\t%s\n", apiKey.Value) - pcio.Fprintf(writer, "Project ID\t%s\n", apiKey.Key.ProjectId) - pcio.Fprintf(writer, "Roles\t%s\n", strings.Join(apiKey.Key.Roles, ", ")) + fmt.Fprintf(writer, "Name\t%s\n", apiKey.Key.Name) + fmt.Fprintf(writer, "ID\t%s\n", apiKey.Key.Id) + fmt.Fprintf(writer, "Value\t%s\n", apiKey.Value) + fmt.Fprintf(writer, "Project ID\t%s\n", apiKey.Key.ProjectId) + fmt.Fprintf(writer, "Roles\t%s\n", strings.Join(apiKey.Key.Roles, ", ")) writer.Flush() } diff --git a/internal/pkg/utils/presenters/auth_status.go b/internal/pkg/utils/presenters/auth_status.go index 637d22c0..df67fa3f 100644 --- a/internal/pkg/utils/presenters/auth_status.go +++ b/internal/pkg/utils/presenters/auth_status.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "golang.org/x/oauth2" ) @@ -17,17 +17,17 @@ func PrintAuthStatus(authStatus AuthStatus) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Authentication Mode\t%s\n", labelUnsetIfEmpty(authStatus.AuthMode)) - pcio.Fprintf(writer, "Default API Key\t%s\n", labelUnsetIfEmpty(authStatus.DefaultAPIKey)) - pcio.Fprintf(writer, "Service Account Client ID\t%s\n", labelUnsetIfEmpty(authStatus.ClientID)) - pcio.Fprintf(writer, "Service Account Client Secret\t%s\n", labelUnsetIfEmpty(authStatus.ClientSecret)) - pcio.Fprintf(writer, "Token Expiry\t%s\n", labelUnsetIfEmpty(authStatus.TokenExpiry)) - pcio.Fprintf(writer, "Token Time Remaining\t%s\n", labelUnsetIfEmpty(authStatus.TokenTimeRemaining)) - pcio.Fprintf(writer, "Token Scope\t%s\n", labelUnsetIfEmpty(authStatus.TokenScope)) - pcio.Fprintf(writer, "Token Organization ID\t%s\n", labelUnsetIfEmpty(authStatus.TokenOrganizationID)) - pcio.Fprintf(writer, "Environment\t%s\n", labelUnsetIfEmpty(authStatus.Environment)) + fmt.Fprintf(writer, "Authentication Mode\t%s\n", labelUnsetIfEmpty(authStatus.AuthMode)) + fmt.Fprintf(writer, "Default API Key\t%s\n", labelUnsetIfEmpty(authStatus.DefaultAPIKey)) + fmt.Fprintf(writer, "Service Account Client ID\t%s\n", labelUnsetIfEmpty(authStatus.ClientID)) + fmt.Fprintf(writer, "Service Account Client Secret\t%s\n", labelUnsetIfEmpty(authStatus.ClientSecret)) + fmt.Fprintf(writer, "Token Expiry\t%s\n", labelUnsetIfEmpty(authStatus.TokenExpiry)) + fmt.Fprintf(writer, "Token Time Remaining\t%s\n", labelUnsetIfEmpty(authStatus.TokenTimeRemaining)) + fmt.Fprintf(writer, "Token Scope\t%s\n", labelUnsetIfEmpty(authStatus.TokenScope)) + fmt.Fprintf(writer, "Token Organization ID\t%s\n", labelUnsetIfEmpty(authStatus.TokenOrganizationID)) + fmt.Fprintf(writer, "Environment\t%s\n", labelUnsetIfEmpty(authStatus.Environment)) writer.Flush() } diff --git a/internal/pkg/utils/presenters/backup.go b/internal/pkg/utils/presenters/backup.go index 617a0dab..fb21c40f 100644 --- a/internal/pkg/utils/presenters/backup.go +++ b/internal/pkg/utils/presenters/backup.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "time" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/pinecone-io/go-pinecone/v5/pinecone" @@ -19,25 +19,25 @@ func PrintBackupTable(backup *pinecone.Backup) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) - - pcio.Fprintf(writer, "Backup ID\t%s\n", backup.BackupId) - pcio.Fprintf(writer, "Name\t%s\n", DisplayOrNone(backup.Name)) - pcio.Fprintf(writer, "Status\t%s\n", colorizeBackupStatus(backup.Status)) - pcio.Fprintf(writer, "Source Index\t%s\n", backup.SourceIndexName) - pcio.Fprintf(writer, "Cloud\t%s\n", backup.Cloud) - pcio.Fprintf(writer, "Region\t%s\n", backup.Region) - pcio.Fprintf(writer, "Record Count\t%s\n", DisplayOrNone(backup.RecordCount)) - pcio.Fprintf(writer, "Namespace Count\t%s\n", DisplayOrNone(backup.NamespaceCount)) - pcio.Fprintf(writer, "Size (bytes)\t%s\n", DisplayOrNone(backup.SizeBytes)) - pcio.Fprintf(writer, "Metric\t%s\n", DisplayOrNone(backup.Metric)) + fmt.Fprint(writer, header) + + fmt.Fprintf(writer, "Backup ID\t%s\n", backup.BackupId) + fmt.Fprintf(writer, "Name\t%s\n", DisplayOrNone(backup.Name)) + fmt.Fprintf(writer, "Status\t%s\n", colorizeBackupStatus(backup.Status)) + fmt.Fprintf(writer, "Source Index\t%s\n", backup.SourceIndexName) + fmt.Fprintf(writer, "Cloud\t%s\n", backup.Cloud) + fmt.Fprintf(writer, "Region\t%s\n", backup.Region) + fmt.Fprintf(writer, "Record Count\t%s\n", DisplayOrNone(backup.RecordCount)) + fmt.Fprintf(writer, "Namespace Count\t%s\n", DisplayOrNone(backup.NamespaceCount)) + fmt.Fprintf(writer, "Size (bytes)\t%s\n", DisplayOrNone(backup.SizeBytes)) + fmt.Fprintf(writer, "Metric\t%s\n", DisplayOrNone(backup.Metric)) schema := "" if backup.Schema != nil { schema = text.InlineJSON(backup.Schema) } - pcio.Fprintf(writer, "Schema\t%s\n", schema) - pcio.Fprintf(writer, "Created At\t%s\n", DisplayOrNone(backup.CreatedAt)) - pcio.Fprintf(writer, "Tags\t%s\n", formatTagsInline(backup.Tags)) + fmt.Fprintf(writer, "Schema\t%s\n", schema) + fmt.Fprintf(writer, "Created At\t%s\n", DisplayOrNone(backup.CreatedAt)) + fmt.Fprintf(writer, "Tags\t%s\n", formatTagsInline(backup.Tags)) writer.Flush() } @@ -51,12 +51,12 @@ func PrintBackupList(list *pinecone.BackupList) { columns := []string{"BACKUP ID", "NAME", "INDEX", "STATUS", "CLOUD/REGION", "RECORDS", "NAMESPACES", "SIZE (B)", "CREATED"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, b := range list.Data { - cloudRegion := pcio.Sprintf("%s/%s", b.Cloud, b.Region) + cloudRegion := fmt.Sprintf("%s/%s", b.Cloud, b.Region) created := DisplayOrNone(b.CreatedAt) - pcio.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", + fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", b.BackupId, DisplayOrNone(b.Name), b.SourceIndexName, @@ -70,7 +70,7 @@ func PrintBackupList(list *pinecone.BackupList) { } if list.Pagination != nil && list.Pagination.Next != "" { - pcio.Fprintf(writer, "\nNext Pagination Token: %s\n", list.Pagination.Next) + fmt.Fprintf(writer, "\nNext Pagination Token: %s\n", list.Pagination.Next) } writer.Flush() @@ -85,15 +85,15 @@ func PrintRestoreJob(job *pinecone.RestoreJob) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Restore Job ID\t%s\n", job.RestoreJobId) - pcio.Fprintf(writer, "Backup ID\t%s\n", job.BackupId) - pcio.Fprintf(writer, "Target Index\t%s\n", job.TargetIndexName) - pcio.Fprintf(writer, "Status\t%s\n", colorizeRestoreJobStatus(job.Status)) - pcio.Fprintf(writer, "Percent Complete\t%s\n", DisplayOrNone(job.PercentComplete)) - pcio.Fprintf(writer, "Created At\t%s\n", formatTime(job.CreatedAt)) - pcio.Fprintf(writer, "Completed At\t%s\n", formatTimePtr(job.CompletedAt)) + fmt.Fprintf(writer, "Restore Job ID\t%s\n", job.RestoreJobId) + fmt.Fprintf(writer, "Backup ID\t%s\n", job.BackupId) + fmt.Fprintf(writer, "Target Index\t%s\n", job.TargetIndexName) + fmt.Fprintf(writer, "Status\t%s\n", colorizeRestoreJobStatus(job.Status)) + fmt.Fprintf(writer, "Percent Complete\t%s\n", DisplayOrNone(job.PercentComplete)) + fmt.Fprintf(writer, "Created At\t%s\n", formatTime(job.CreatedAt)) + fmt.Fprintf(writer, "Completed At\t%s\n", formatTimePtr(job.CompletedAt)) writer.Flush() } @@ -107,10 +107,10 @@ func PrintRestoreJobList(list *pinecone.RestoreJobList) { columns := []string{"RESTORE JOB ID", "BACKUP ID", "TARGET INDEX", "STATUS", "PERCENT", "CREATED", "COMPLETED"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) for _, job := range list.Data { - pcio.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", + fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", job.RestoreJobId, job.BackupId, job.TargetIndexName, @@ -122,7 +122,7 @@ func PrintRestoreJobList(list *pinecone.RestoreJobList) { } if list.Pagination != nil && list.Pagination.Next != "" { - pcio.Fprintf(writer, "\nNext Pagination Token: %s\n", list.Pagination.Next) + fmt.Fprintf(writer, "\nNext Pagination Token: %s\n", list.Pagination.Next) } writer.Flush() diff --git a/internal/pkg/utils/presenters/collection_description.go b/internal/pkg/utils/presenters/collection_description.go index f47d4146..6d583ddd 100644 --- a/internal/pkg/utils/presenters/collection_description.go +++ b/internal/pkg/utils/presenters/collection_description.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -20,14 +20,14 @@ func PrintDescribeCollectionTable(coll *pinecone.Collection) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) - - pcio.Fprintf(writer, "Name\t%s\n", coll.Name) - pcio.Fprintf(writer, "State\t%s\n", ColorizeCollectionStatus(coll.Status)) - pcio.Fprintf(writer, "Dimension\t%d\n", coll.Dimension) - pcio.Fprintf(writer, "Size\t%d\n", coll.Size) - pcio.Fprintf(writer, "VectorCount\t%d\n", coll.VectorCount) - pcio.Fprintf(writer, "Environment\t%s\n", coll.Environment) + fmt.Fprint(writer, header) + + fmt.Fprintf(writer, "Name\t%s\n", coll.Name) + fmt.Fprintf(writer, "State\t%s\n", ColorizeCollectionStatus(coll.Status)) + fmt.Fprintf(writer, "Dimension\t%d\n", coll.Dimension) + fmt.Fprintf(writer, "Size\t%d\n", coll.Size) + fmt.Fprintf(writer, "VectorCount\t%d\n", coll.VectorCount) + fmt.Fprintf(writer, "Environment\t%s\n", coll.Environment) writer.Flush() } diff --git a/internal/pkg/utils/presenters/describe_index_stats.go b/internal/pkg/utils/presenters/describe_index_stats.go index 6e180cd6..463415b8 100644 --- a/internal/pkg/utils/presenters/describe_index_stats.go +++ b/internal/pkg/utils/presenters/describe_index_stats.go @@ -1,9 +1,9 @@ package presenters import ( + "fmt" "strings" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -16,29 +16,29 @@ func PrintDescribeIndexStatsTable(resp *pinecone.DescribeIndexStatsResponse) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) dimension := uint32(0) if resp.Dimension != nil { dimension = *resp.Dimension } - pcio.Fprintf(writer, "Dimension\t%d\n", dimension) - pcio.Fprintf(writer, "Index Fullness\t%f\n", resp.IndexFullness) - pcio.Fprintf(writer, "Total Vector Count\t%d\n", resp.TotalVectorCount) + fmt.Fprintf(writer, "Dimension\t%d\n", dimension) + fmt.Fprintf(writer, "Index Fullness\t%f\n", resp.IndexFullness) + fmt.Fprintf(writer, "Total Vector Count\t%d\n", resp.TotalVectorCount) if len(resp.Namespaces) == 0 { - pcio.Fprintf(writer, "Namespaces\t\n") + fmt.Fprintf(writer, "Namespaces\t\n") } else { - pcio.Fprintf(writer, "Namespaces\n") - pcio.Fprintf(writer, "\tNAME\tVECTOR COUNT\n") + fmt.Fprintf(writer, "Namespaces\n") + fmt.Fprintf(writer, "\tNAME\tVECTOR COUNT\n") names := make([]string, 0, len(resp.Namespaces)) for name := range resp.Namespaces { names = append(names, name) } for _, name := range names { - pcio.Fprintf(writer, "\t%s\t%d\n", name, resp.Namespaces[name].VectorCount) + fmt.Fprintf(writer, "\t%s\t%d\n", name, resp.Namespaces[name].VectorCount) } } diff --git a/internal/pkg/utils/presenters/fetch_vectors.go b/internal/pkg/utils/presenters/fetch_vectors.go index 00b33bb3..c37feadb 100644 --- a/internal/pkg/utils/presenters/fetch_vectors.go +++ b/internal/pkg/utils/presenters/fetch_vectors.go @@ -1,9 +1,9 @@ package presenters import ( + "fmt" "strings" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -47,15 +47,15 @@ func PrintFetchVectorsTable(results *FetchVectorsResults) { // Header Block if results.Namespace != "" { - pcio.Fprintf(writer, "Namespace: %s\n", results.Namespace) + fmt.Fprintf(writer, "Namespace: %s\n", results.Namespace) } if results.Usage != nil { - pcio.Fprintf(writer, "Usage: %d (read units)\n", results.Usage.ReadUnits) + fmt.Fprintf(writer, "Usage: %d (read units)\n", results.Usage.ReadUnits) } // Table Header columns := []string{"ID", "DIMENSION", "VALUES", "SPARSE VALUES", "METADATA"} - pcio.Fprintln(writer, strings.Join(columns, "\t")) + fmt.Fprintln(writer, strings.Join(columns, "\t")) // Rows for id, vector := range results.Vectors { @@ -73,8 +73,8 @@ func PrintFetchVectorsTable(results *FetchVectorsResults) { } preview := previewSliceFloat32(vector.Values, 3) - row := []string{id, pcio.Sprintf("%d", dim), preview, pcio.Sprintf("%d", sparseDim), metadata} - pcio.Fprintln(writer, strings.Join(row, "\t")) + row := []string{id, fmt.Sprintf("%d", dim), preview, fmt.Sprintf("%d", sparseDim), metadata} + fmt.Fprintln(writer, strings.Join(row, "\t")) } writer.Flush() diff --git a/internal/pkg/utils/presenters/index_description.go b/internal/pkg/utils/presenters/index_description.go index 6e6ea50d..91ab3fec 100644 --- a/internal/pkg/utils/presenters/index_description.go +++ b/internal/pkg/utils/presenters/index_description.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/pinecone-io/go-pinecone/v5/pinecone" @@ -41,14 +41,14 @@ func PrintDescribeIndexTable(idx *pinecone.Index) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Name\t%s\n", idx.Name) - pcio.Fprintf(writer, "Dimension\t%s\n", DisplayOrNone(idx.Dimension)) - pcio.Fprintf(writer, "Metric\t%s\n", string(idx.Metric)) - pcio.Fprintf(writer, "Deletion Protection\t%s\n", ColorizeDeletionProtection(idx.DeletionProtection)) - pcio.Fprintf(writer, "Vector Type\t%s\n", DisplayOrNone(idx.VectorType)) - pcio.Fprintf(writer, "\n") + fmt.Fprintf(writer, "Name\t%s\n", idx.Name) + fmt.Fprintf(writer, "Dimension\t%s\n", DisplayOrNone(idx.Dimension)) + fmt.Fprintf(writer, "Metric\t%s\n", string(idx.Metric)) + fmt.Fprintf(writer, "Deletion Protection\t%s\n", ColorizeDeletionProtection(idx.DeletionProtection)) + fmt.Fprintf(writer, "Vector Type\t%s\n", DisplayOrNone(idx.VectorType)) + fmt.Fprintf(writer, "\n") stateVal := "" readyVal := "" @@ -56,85 +56,85 @@ func PrintDescribeIndexTable(idx *pinecone.Index) { stateVal = ColorizeState(idx.Status.State) readyVal = ColorizeBool(idx.Status.Ready) } - pcio.Fprintf(writer, "State\t%s\n", stateVal) - pcio.Fprintf(writer, "Ready\t%s\n", readyVal) - pcio.Fprintf(writer, "Host\t%s\n", style.Emphasis(idx.Host)) - pcio.Fprintf(writer, "Private Host\t%s\n", DisplayOrNone(idx.PrivateHost)) - pcio.Fprintf(writer, "\n") + fmt.Fprintf(writer, "State\t%s\n", stateVal) + fmt.Fprintf(writer, "Ready\t%s\n", readyVal) + fmt.Fprintf(writer, "Host\t%s\n", style.Emphasis(idx.Host)) + fmt.Fprintf(writer, "Private Host\t%s\n", DisplayOrNone(idx.PrivateHost)) + fmt.Fprintf(writer, "\n") switch { case idx.Spec == nil: // nil spec - pcio.Fprintf(writer, "Spec\t%s\n", "") + fmt.Fprintf(writer, "Spec\t%s\n", "") case idx.Spec.Serverless != nil: // serverless spec - pcio.Fprintf(writer, "Spec\t%s\n", "serverless") + fmt.Fprintf(writer, "Spec\t%s\n", "serverless") serverless := idx.Spec.Serverless if serverless != nil { - pcio.Fprintf(writer, "Cloud\t%s\n", serverless.Cloud) - pcio.Fprintf(writer, "Region\t%s\n", serverless.Region) - pcio.Fprintf(writer, "Source Collection\t%s\n", DisplayOrNone(serverless.SourceCollection)) + fmt.Fprintf(writer, "Cloud\t%s\n", serverless.Cloud) + fmt.Fprintf(writer, "Region\t%s\n", serverless.Region) + fmt.Fprintf(writer, "Source Collection\t%s\n", DisplayOrNone(serverless.SourceCollection)) schemaVal := "" if serverless.Schema != nil { schemaVal = text.InlineJSON(serverless.Schema) } - pcio.Fprintf(writer, "Schema\t%s\n", schemaVal) + fmt.Fprintf(writer, "Schema\t%s\n", schemaVal) readCapacityVal := "" if serverless.ReadCapacity != nil { readCapacityVal = text.InlineJSON(serverless.ReadCapacity) } - pcio.Fprintf(writer, "Read Capacity\t%s\n", readCapacityVal) + fmt.Fprintf(writer, "Read Capacity\t%s\n", readCapacityVal) } else { - pcio.Fprintf(writer, "Cloud\t%s\n", "") - pcio.Fprintf(writer, "Region\t%s\n", "") - pcio.Fprintf(writer, "Source Collection\t%s\n", "") + fmt.Fprintf(writer, "Cloud\t%s\n", "") + fmt.Fprintf(writer, "Region\t%s\n", "") + fmt.Fprintf(writer, "Source Collection\t%s\n", "") } case idx.Spec.BYOC != nil: // BYOC spec - pcio.Fprintf(writer, "Spec\t%s\n", "byoc") + fmt.Fprintf(writer, "Spec\t%s\n", "byoc") byoc := idx.Spec.BYOC - pcio.Fprintf(writer, "Environment\t%s\n", byoc.Environment) + fmt.Fprintf(writer, "Environment\t%s\n", byoc.Environment) schemaVal := "" if byoc.Schema != nil { schemaVal = text.InlineJSON(byoc.Schema) } - pcio.Fprintf(writer, "Schema\t%s\n", schemaVal) + fmt.Fprintf(writer, "Schema\t%s\n", schemaVal) case idx.Spec.Pod != nil: // pod spec - pcio.Fprintf(writer, "Spec\t%s\n", "pod") + fmt.Fprintf(writer, "Spec\t%s\n", "pod") pod := idx.Spec.Pod if pod != nil { - pcio.Fprintf(writer, "Environment\t%s\n", pod.Environment) - pcio.Fprintf(writer, "PodType\t%s\n", pod.PodType) - pcio.Fprintf(writer, "Replicas\t%d\n", pod.Replicas) - pcio.Fprintf(writer, "ShardCount\t%d\n", pod.ShardCount) - pcio.Fprintf(writer, "PodCount\t%d\n", pod.PodCount) + fmt.Fprintf(writer, "Environment\t%s\n", pod.Environment) + fmt.Fprintf(writer, "PodType\t%s\n", pod.PodType) + fmt.Fprintf(writer, "Replicas\t%d\n", pod.Replicas) + fmt.Fprintf(writer, "ShardCount\t%d\n", pod.ShardCount) + fmt.Fprintf(writer, "PodCount\t%d\n", pod.PodCount) metadataConfig := "" if pod.MetadataConfig != nil { metadataConfig = text.InlineJSON(pod.MetadataConfig) } - pcio.Fprintf(writer, "MetadataConfig\t%s\n", metadataConfig) - pcio.Fprintf(writer, "Source Collection\t%s\n", DisplayOrNone(pod.SourceCollection)) + fmt.Fprintf(writer, "MetadataConfig\t%s\n", metadataConfig) + fmt.Fprintf(writer, "Source Collection\t%s\n", DisplayOrNone(pod.SourceCollection)) } else { - pcio.Fprintf(writer, "Environment\t%s\n", "") - pcio.Fprintf(writer, "PodType\t%s\n", "") - pcio.Fprintf(writer, "Replicas\t%s\n", "") - pcio.Fprintf(writer, "ShardCount\t%s\n", "") - pcio.Fprintf(writer, "PodCount\t%s\n", "") - pcio.Fprintf(writer, "MetadataConfig\t%s\n", "") - pcio.Fprintf(writer, "Source Collection\t%s\n", "") + fmt.Fprintf(writer, "Environment\t%s\n", "") + fmt.Fprintf(writer, "PodType\t%s\n", "") + fmt.Fprintf(writer, "Replicas\t%s\n", "") + fmt.Fprintf(writer, "ShardCount\t%s\n", "") + fmt.Fprintf(writer, "PodCount\t%s\n", "") + fmt.Fprintf(writer, "MetadataConfig\t%s\n", "") + fmt.Fprintf(writer, "Source Collection\t%s\n", "") } default: // unknown spec - pcio.Fprintf(writer, "Spec\t%s\n", "unknown") + fmt.Fprintf(writer, "Spec\t%s\n", "unknown") } - pcio.Fprintf(writer, "\n") + fmt.Fprintf(writer, "\n") if idx.Embed != nil { - pcio.Fprintf(writer, "Model\t%s\n", idx.Embed.Model) - pcio.Fprintf(writer, "Field Map\t%s\n", text.InlineJSON(idx.Embed.FieldMap)) - pcio.Fprintf(writer, "Read Parameters\t%s\n", text.InlineJSON(idx.Embed.ReadParameters)) - pcio.Fprintf(writer, "Write Parameters\t%s\n", text.InlineJSON(idx.Embed.WriteParameters)) - pcio.Fprintf(writer, "\n") + fmt.Fprintf(writer, "Model\t%s\n", idx.Embed.Model) + fmt.Fprintf(writer, "Field Map\t%s\n", text.InlineJSON(idx.Embed.FieldMap)) + fmt.Fprintf(writer, "Read Parameters\t%s\n", text.InlineJSON(idx.Embed.ReadParameters)) + fmt.Fprintf(writer, "Write Parameters\t%s\n", text.InlineJSON(idx.Embed.WriteParameters)) + fmt.Fprintf(writer, "\n") } if idx.Tags != nil { - pcio.Fprintf(writer, "Tags\t%s\n", text.InlineJSON(idx.Tags)) + fmt.Fprintf(writer, "Tags\t%s\n", text.InlineJSON(idx.Tags)) } writer.Flush() diff --git a/internal/pkg/utils/presenters/list_vectors.go b/internal/pkg/utils/presenters/list_vectors.go index 1440000f..890443be 100644 --- a/internal/pkg/utils/presenters/list_vectors.go +++ b/internal/pkg/utils/presenters/list_vectors.go @@ -1,9 +1,9 @@ package presenters import ( + "fmt" "strings" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -16,15 +16,15 @@ func PrintListVectorsTable(resp *pinecone.ListVectorsResponse) { // Header block if resp.Namespace != "" { - pcio.Fprintf(writer, "Namespace: %s\n", resp.Namespace) + fmt.Fprintf(writer, "Namespace: %s\n", resp.Namespace) } if resp.Usage != nil { - pcio.Fprintf(writer, "Usage: %d (read units)\n", resp.Usage.ReadUnits) + fmt.Fprintf(writer, "Usage: %d (read units)\n", resp.Usage.ReadUnits) } // Table header columns := []string{"ID"} - pcio.Fprintln(writer, strings.Join(columns, "\t")) + fmt.Fprintln(writer, strings.Join(columns, "\t")) // Rows for _, vectorId := range resp.VectorIds { @@ -32,12 +32,12 @@ func PrintListVectorsTable(resp *pinecone.ListVectorsResponse) { if vectorId != nil { id = *vectorId } - pcio.Fprintln(writer, id) + fmt.Fprintln(writer, id) } // Pagination footer if resp.NextPaginationToken != nil { - pcio.Fprintf(writer, "Next pagination token: %s\n", *resp.NextPaginationToken) + fmt.Fprintf(writer, "Next pagination token: %s\n", *resp.NextPaginationToken) } writer.Flush() diff --git a/internal/pkg/utils/presenters/namespace_description.go b/internal/pkg/utils/presenters/namespace_description.go index 7072cc06..845e8672 100644 --- a/internal/pkg/utils/presenters/namespace_description.go +++ b/internal/pkg/utils/presenters/namespace_description.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -20,22 +20,22 @@ func PrintDescribeNamespaceTable(ns *pinecone.NamespaceDescription) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Name\t%s\n", ns.Name) - pcio.Fprintf(writer, "Record Count\t%d\n", ns.RecordCount) + fmt.Fprintf(writer, "Name\t%s\n", ns.Name) + fmt.Fprintf(writer, "Record Count\t%d\n", ns.RecordCount) indexedFieldsVal := "" if ns.IndexedFields != nil { indexedFieldsVal = text.InlineJSON(ns.IndexedFields) } - pcio.Fprintf(writer, "Indexed Fields\t%s\n", indexedFieldsVal) + fmt.Fprintf(writer, "Indexed Fields\t%s\n", indexedFieldsVal) schemaVal := "" if ns.Schema != nil { schemaVal = text.InlineJSON(ns.Schema) } - pcio.Fprintf(writer, "Schema\t%s\n", schemaVal) + fmt.Fprintf(writer, "Schema\t%s\n", schemaVal) writer.Flush() } diff --git a/internal/pkg/utils/presenters/organization_description.go b/internal/pkg/utils/presenters/organization_description.go index ae3d7933..bf0d1a96 100644 --- a/internal/pkg/utils/presenters/organization_description.go +++ b/internal/pkg/utils/presenters/organization_description.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -19,15 +19,15 @@ func PrintDescribeOrganizationTable(org *pinecone.Organization) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) - - pcio.Fprintf(writer, "Name\t%s\n", org.Name) - pcio.Fprintf(writer, "ID\t%s\n", org.Id) - pcio.Fprintf(writer, "Created At\t%s\n", org.CreatedAt.String()) - pcio.Fprintf(writer, "Payment Status\t%s\n", org.PaymentStatus) - pcio.Fprintf(writer, "Plan\t%s\n", org.Plan) - pcio.Fprintf(writer, "Support Tier\t%s\n", org.SupportTier) - pcio.Fprintf(writer, "\n") + fmt.Fprint(writer, header) + + fmt.Fprintf(writer, "Name\t%s\n", org.Name) + fmt.Fprintf(writer, "ID\t%s\n", org.Id) + fmt.Fprintf(writer, "Created At\t%s\n", org.CreatedAt.String()) + fmt.Fprintf(writer, "Payment Status\t%s\n", org.PaymentStatus) + fmt.Fprintf(writer, "Plan\t%s\n", org.Plan) + fmt.Fprintf(writer, "Support Tier\t%s\n", org.SupportTier) + fmt.Fprintf(writer, "\n") writer.Flush() diff --git a/internal/pkg/utils/presenters/project_description.go b/internal/pkg/utils/presenters/project_description.go index ee3489dc..a7e1cbab 100644 --- a/internal/pkg/utils/presenters/project_description.go +++ b/internal/pkg/utils/presenters/project_description.go @@ -1,11 +1,11 @@ package presenters import ( + "fmt" "strconv" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -20,15 +20,15 @@ func PrintDescribeProjectTable(proj *pinecone.Project) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Name\t%s\n", proj.Name) - pcio.Fprintf(writer, "ID\t%s\n", proj.Id) - pcio.Fprintf(writer, "Organization ID\t%s\n", proj.OrganizationId) - pcio.Fprintf(writer, "Created At\t%s\n", proj.CreatedAt.String()) - pcio.Fprintf(writer, "Force Encryption\t%s\n", strconv.FormatBool(proj.ForceEncryptionWithCmek)) - pcio.Fprintf(writer, "Max Pods\t%d\n", proj.MaxPods) - pcio.Fprintf(writer, "\n") + fmt.Fprintf(writer, "Name\t%s\n", proj.Name) + fmt.Fprintf(writer, "ID\t%s\n", proj.Id) + fmt.Fprintf(writer, "Organization ID\t%s\n", proj.OrganizationId) + fmt.Fprintf(writer, "Created At\t%s\n", proj.CreatedAt.String()) + fmt.Fprintf(writer, "Force Encryption\t%s\n", strconv.FormatBool(proj.ForceEncryptionWithCmek)) + fmt.Fprintf(writer, "Max Pods\t%d\n", proj.MaxPods) + fmt.Fprintf(writer, "\n") writer.Flush() } diff --git a/internal/pkg/utils/presenters/query_vectors.go b/internal/pkg/utils/presenters/query_vectors.go index c52a301e..8270589b 100644 --- a/internal/pkg/utils/presenters/query_vectors.go +++ b/internal/pkg/utils/presenters/query_vectors.go @@ -1,9 +1,9 @@ package presenters import ( + "fmt" "strings" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -17,10 +17,10 @@ func PrintQueryVectorsTable(resp *pinecone.QueryVectorsResponse) { // Header Block if resp.Namespace != "" { - pcio.Fprintf(writer, "Namespace: %s\n", resp.Namespace) + fmt.Fprintf(writer, "Namespace: %s\n", resp.Namespace) } if resp.Usage != nil { - pcio.Fprintf(writer, "Usage: %d (read units)\n", resp.Usage.ReadUnits) + fmt.Fprintf(writer, "Usage: %d (read units)\n", resp.Usage.ReadUnits) } // Detect which columns to show @@ -54,14 +54,14 @@ func PrintQueryVectorsTable(resp *pinecone.QueryVectorsResponse) { if hasMetadata { cols = append(cols, "METADATA") } - pcio.Fprintln(writer, strings.Join(cols, "\t")) + fmt.Fprintln(writer, strings.Join(cols, "\t")) // Rows for _, match := range resp.Matches { if match == nil || match.Vector == nil { continue } - row := []string{match.Vector.Id, pcio.Sprintf("%f", match.Score)} + row := []string{match.Vector.Id, fmt.Sprintf("%f", match.Score)} if hasDense { values := "" @@ -86,7 +86,7 @@ func PrintQueryVectorsTable(resp *pinecone.QueryVectorsResponse) { row = append(row, metadata) } - pcio.Fprintln(writer, strings.Join(row, "\t")) + fmt.Fprintln(writer, strings.Join(row, "\t")) } writer.Flush() diff --git a/internal/pkg/utils/presenters/search_records.go b/internal/pkg/utils/presenters/search_records.go index cfdb58ec..ef13851c 100644 --- a/internal/pkg/utils/presenters/search_records.go +++ b/internal/pkg/utils/presenters/search_records.go @@ -1,10 +1,10 @@ package presenters import ( + "fmt" "sort" "strings" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/text" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -17,20 +17,20 @@ func PrintSearchRecordsTable(resp *pinecone.SearchRecordsResponse) { } if resp.Usage.ReadUnits > 0 { - pcio.Fprintf(writer, "Usage: %d (read units)\n", resp.Usage.ReadUnits) + fmt.Fprintf(writer, "Usage: %d (read units)\n", resp.Usage.ReadUnits) } if resp.Usage.EmbedTotalTokens != nil { - pcio.Fprintf(writer, "Embed tokens: %d\n", *resp.Usage.EmbedTotalTokens) + fmt.Fprintf(writer, "Embed tokens: %d\n", *resp.Usage.EmbedTotalTokens) } if resp.Usage.RerankUnits != nil { - pcio.Fprintf(writer, "Rerank units: %d\n", *resp.Usage.RerankUnits) + fmt.Fprintf(writer, "Rerank units: %d\n", *resp.Usage.RerankUnits) } - pcio.Fprintln(writer, "ID\tSCORE\tFIELDS") + fmt.Fprintln(writer, "ID\tSCORE\tFIELDS") for _, hit := range resp.Result.Hits { fields := previewFields(hit.Fields, 3) - pcio.Fprintf(writer, "%s\t%f\t%s\n", hit.Id, hit.Score, fields) + fmt.Fprintf(writer, "%s\t%f\t%s\n", hit.Id, hit.Score, fields) } writer.Flush() diff --git a/internal/pkg/utils/presenters/tabwriter.go b/internal/pkg/utils/presenters/tabwriter.go index 0fdfaf75..633adc85 100644 --- a/internal/pkg/utils/presenters/tabwriter.go +++ b/internal/pkg/utils/presenters/tabwriter.go @@ -1,10 +1,9 @@ package presenters import ( + "fmt" "os" "text/tabwriter" - - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" ) func NewTabWriter() *tabwriter.Writer { @@ -18,7 +17,7 @@ func PrintEmptyState(writer *tabwriter.Writer, resource string) bool { if resource == "" { resource = "data" } - pcio.Fprintf(writer, "No %s available.\n", resource) + fmt.Fprintf(writer, "No %s available.\n", resource) writer.Flush() return true } diff --git a/internal/pkg/utils/presenters/target_context.go b/internal/pkg/utils/presenters/target_context.go index 37e96f77..48955c84 100644 --- a/internal/pkg/utils/presenters/target_context.go +++ b/internal/pkg/utils/presenters/target_context.go @@ -1,12 +1,12 @@ package presenters import ( + "fmt" "strings" "github.com/pinecone-io/cli/internal/pkg/utils/configuration/secrets" "github.com/pinecone-io/cli/internal/pkg/utils/configuration/state" "github.com/pinecone-io/cli/internal/pkg/utils/log" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/style" ) @@ -31,16 +31,16 @@ func PrintTargetContext(context *state.TargetContext) { columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) // Get API key for presentational layer defaultAPIKeyMasked := MaskHeadTail(secrets.DefaultAPIKey.Get(), 4, 4) - pcio.Fprintf(writer, "Organization\t%s\n", labelUnsetIfEmpty(string(context.Organization.Name))) - pcio.Fprintf(writer, "Organization ID\t%s\n", labelUnsetIfEmpty(string(context.Organization.Id))) - pcio.Fprintf(writer, "Project\t%s\n", labelUnsetIfEmpty(string(context.Project.Name))) - pcio.Fprintf(writer, "Project ID\t%s\n", labelUnsetIfEmpty(string(context.Project.Id))) - pcio.Fprintf(writer, "Default API Key\t%s\n", labelUnsetIfEmpty(defaultAPIKeyMasked)) + fmt.Fprintf(writer, "Organization\t%s\n", labelUnsetIfEmpty(string(context.Organization.Name))) + fmt.Fprintf(writer, "Organization ID\t%s\n", labelUnsetIfEmpty(string(context.Organization.Id))) + fmt.Fprintf(writer, "Project\t%s\n", labelUnsetIfEmpty(string(context.Project.Name))) + fmt.Fprintf(writer, "Project ID\t%s\n", labelUnsetIfEmpty(string(context.Project.Id))) + fmt.Fprintf(writer, "Default API Key\t%s\n", labelUnsetIfEmpty(defaultAPIKeyMasked)) writer.Flush() } diff --git a/internal/pkg/utils/presenters/update_vector.go b/internal/pkg/utils/presenters/update_vector.go index a88aeac5..1e2dd578 100644 --- a/internal/pkg/utils/presenters/update_vector.go +++ b/internal/pkg/utils/presenters/update_vector.go @@ -1,9 +1,9 @@ package presenters import ( + "fmt" "strings" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/go-pinecone/v5/pinecone" ) @@ -16,9 +16,9 @@ func PrintUpdateVectorsByMetadataTable(resp *pinecone.UpdateVectorsByMetadataRes columns := []string{"ATTRIBUTE", "VALUE"} header := strings.Join(columns, "\t") + "\n" - pcio.Fprint(writer, header) + fmt.Fprint(writer, header) - pcio.Fprintf(writer, "Matched Records\t%d\n", resp.MatchedRecords) + fmt.Fprintf(writer, "Matched Records\t%d\n", resp.MatchedRecords) writer.Flush() } diff --git a/internal/pkg/utils/prompt/list.go b/internal/pkg/utils/prompt/list.go index 86f4085d..50de7500 100644 --- a/internal/pkg/utils/prompt/list.go +++ b/internal/pkg/utils/prompt/list.go @@ -1,13 +1,13 @@ package prompt import ( + "fmt" "io" "strings" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" ) type ListModel struct { @@ -110,7 +110,7 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list return } - str := pcio.Sprintf("%d. %s", index+1, i) + str := fmt.Sprintf("%d. %s", index+1, i) fn := itemStyle.Render if index == m.Index() { @@ -119,5 +119,5 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list } } - pcio.Fprint(w, fn(str)) + fmt.Fprint(w, fn(str)) } diff --git a/internal/pkg/utils/sdk/client.go b/internal/pkg/utils/sdk/client.go index 8a666caa..ae9f1408 100644 --- a/internal/pkg/utils/sdk/client.go +++ b/internal/pkg/utils/sdk/client.go @@ -3,6 +3,7 @@ package sdk import ( "context" "crypto/rand" + "fmt" "io" "os" @@ -14,7 +15,6 @@ import ( "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/oauth" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" "github.com/pinecone-io/cli/internal/pkg/utils/style" "github.com/pinecone-io/go-pinecone/v5/pinecone" @@ -154,7 +154,7 @@ func NewPineconeAdminClient(ctx context.Context) *pinecone.AdminClient { func NewIndexConnection(ctx context.Context, pc *pinecone.Client, indexName string, namespace string) (*pinecone.IndexConnection, error) { index, err := pc.DescribeIndex(ctx, indexName) if err != nil { - return nil, pcio.Errorf("failed to describe index: %w", err) + return nil, fmt.Errorf("failed to describe index: %w", err) } // Use private_host for BYOC if it exists @@ -168,7 +168,7 @@ func NewIndexConnection(ctx context.Context, pc *pinecone.Client, indexName stri Namespace: namespace, }) if err != nil { - return nil, pcio.Errorf("failed to create index connection: %w", err) + return nil, fmt.Errorf("failed to create index connection: %w", err) } return ic, nil } @@ -194,7 +194,7 @@ func getCLIAPIKeyForProject(ctx context.Context, ac *pinecone.AdminClient, proje }) if err != nil { msg.FailMsg("Failed to create a CLI managed API key for project %s: %s", style.Emphasis(project.Name), err) - return "", pcio.Errorf("failed to create a CLI managed API key for project: %w", err) + return "", fmt.Errorf("failed to create a CLI managed API key for project: %w", err) } managedKey = secrets.ManagedKey{ diff --git a/internal/pkg/utils/style/spinner.go b/internal/pkg/utils/style/spinner.go index 4e9ca9d5..cd5e8673 100644 --- a/internal/pkg/utils/style/spinner.go +++ b/internal/pkg/utils/style/spinner.go @@ -1,12 +1,12 @@ package style import ( + "os" "time" "github.com/briandowns/spinner" "github.com/pinecone-io/cli/internal/pkg/utils/exit" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" ) var ( @@ -34,7 +34,7 @@ func loading(initialMsg, doneMsg, failMsg string, fn func() error) error { s.Prefix = initialMsg s.FinalMSG = doneMsg s.HideCursor = true - s.Writer = pcio.Messages + s.Writer = os.Stdout if err := s.Color(spinnerColor); err != nil { exit.Error(err, "Error setting spinner color") diff --git a/internal/pkg/utils/style/typography.go b/internal/pkg/utils/style/typography.go index dd717e02..32732339 100644 --- a/internal/pkg/utils/style/typography.go +++ b/internal/pkg/utils/style/typography.go @@ -1,8 +1,9 @@ package style import ( + "fmt" + "github.com/fatih/color" - "github.com/pinecone-io/cli/internal/pkg/utils/pcio" ) func Emphasis(s string) string { @@ -26,7 +27,7 @@ func Hint(s string) string { } func CodeHint(templateString string, codeString string) string { - return applyStyle("Hint: ", color.Faint) + pcio.Sprintf(templateString, Code(codeString)) + return applyStyle("Hint: ", color.Faint) + fmt.Sprintf(templateString, Code(codeString)) } func SuccessMsg(s string) string { diff --git a/test/e2e/helpers/cli.go b/test/e2e/helpers/cli.go index fcdcd81c..4aad3185 100644 --- a/test/e2e/helpers/cli.go +++ b/test/e2e/helpers/cli.go @@ -95,7 +95,7 @@ func (c *CLI) RunCtx(ctx context.Context, args ...string) (string, string, error out, err := cmd.CombinedOutput() stdout := string(out) - // Cobra writes most output to stdout via their pcio helpers; retain single stream + // Cobra writes most output to stdout; retain single stream // We still return stderr string for API compatibility. stderr := "" if ctx.Err() == context.DeadlineExceeded { From 80271a89da423cc4827a3284f050ba6c309c4050 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Fri, 20 Mar 2026 13:42:59 -0400 Subject: [PATCH 2/2] add explicit Fprint statements to stdout --- internal/pkg/cli/command/apiKey/describe.go | 3 ++- internal/pkg/cli/command/apiKey/update.go | 3 ++- internal/pkg/cli/command/config/get_api_key.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/pkg/cli/command/apiKey/describe.go b/internal/pkg/cli/command/apiKey/describe.go index 4d8d0bf5..794cc3df 100644 --- a/internal/pkg/cli/command/apiKey/describe.go +++ b/internal/pkg/cli/command/apiKey/describe.go @@ -2,6 +2,7 @@ package apiKey import ( "fmt" + "os" "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/help" @@ -40,7 +41,7 @@ func NewDescribeAPIKeyCmd() *cobra.Command { if options.json { json := text.IndentJSON(apiKey) - fmt.Println(json) + fmt.Fprint(os.Stdout, json) } else { presenters.PrintDescribeAPIKeyTable(apiKey) } diff --git a/internal/pkg/cli/command/apiKey/update.go b/internal/pkg/cli/command/apiKey/update.go index 2a44db7e..099bf5c7 100644 --- a/internal/pkg/cli/command/apiKey/update.go +++ b/internal/pkg/cli/command/apiKey/update.go @@ -2,6 +2,7 @@ package apiKey import ( "fmt" + "os" "github.com/pinecone-io/cli/internal/pkg/utils/exit" "github.com/pinecone-io/cli/internal/pkg/utils/help" @@ -51,7 +52,7 @@ func NewUpdateAPIKeyCmd() *cobra.Command { if options.json { json := text.IndentJSON(apiKey) - fmt.Println(json) + fmt.Fprint(os.Stdout, json) return } diff --git a/internal/pkg/cli/command/config/get_api_key.go b/internal/pkg/cli/command/config/get_api_key.go index 02af13c3..2b30b2d5 100644 --- a/internal/pkg/cli/command/config/get_api_key.go +++ b/internal/pkg/cli/command/config/get_api_key.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "os" "github.com/pinecone-io/cli/internal/pkg/utils/configuration/secrets" "github.com/pinecone-io/cli/internal/pkg/utils/help" @@ -27,7 +28,7 @@ func NewGetApiKeyCmd() *cobra.Command { if !options.reveal { apiKey = presenters.MaskHeadTail(apiKey, 4, 4) } - fmt.Printf("Current default API key: %s", apiKey) + fmt.Fprintf(os.Stdout, "Current default API key: %s", apiKey) }, }