Add --json to remaining delete / utility commands#69
Conversation
…gents consuming CLI output had no to way to programmatically confirm the outcome of delete operations or identity/version queries
|
|
||
| fmt.Printf("Version: %s\n", build.Version) | ||
| fmt.Printf("SHA: %s\n", build.Commit) | ||
| fmt.Printf("Built: %s\n", build.Date) |
There was a problem hiding this comment.
Version non-JSON output bypasses quiet mode
Medium Severity
The non-JSON output path was changed from pcio.Printf to fmt.Printf, which means pc version --quiet (or -q) no longer suppresses output. The global --quiet flag works by calling pcio.SetQuiet(true) in the root command's PersistentPreRun, and only pcio.* functions honor that setting. Other commands in the codebase (e.g., apiKey/list.go, target/target.go) still use pcio.Printf for non-JSON stdout output. The JSON path correctly uses fmt.Println (explicit opt-in output), but the plain-text fallback needs to remain pcio.Printf to preserve quiet-mode behavior.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| if options.json { | ||
| fmt.Println(text.IndentJSON(struct { | ||
| Email string `json:"email"` | ||
| OrgId string `json:"organization_id"` |
There was a problem hiding this comment.
JSON field name doesn't match documented spec
Medium Severity
The inline struct uses json:"organization_id" but the PR specification and local testing output both show the field name as org_id. The actual JSON output will contain "organization_id" instead of "org_id", breaking the documented contract that agentic consumers would rely on. Both whoami/whoami.go and auth/whoami.go have the same mismatch.
Additional Locations (1)
There was a problem hiding this comment.
Updated to "organization_id" intentionally. I've updated the PR description, testing, and examples.


Problem
There are a number of commands that currently either don't support
--json, or the flag is used improperly, and there's still non-JSON output going through stdout. This PR tackles adding--jsonto existing commands where it's not supported, and constructing coherent JSON payloads for the output in these situations.In some cases like
deleteandlogincommands where there's no explicit returned struct from the SDK, we fabricate a minimal response struct inline to allow for returning structured, relevant data from the command. This is important for agentic contexts where informative output from commands is essential.Solution
-j/--jsonflag to all remaining delete commands:pc index delete,pc collection delete,pc backup delete,pc index namespace delete, andpc apiKey delete. Each emits a consistent delete envelope to stdout:{"deleted": true, <identity fields>}, where identity fields are the natural key(s) for that resource (name,id,namespace/index, etc.).-j/--jsonflag to utility commands:pc logout/pc auth logoutemit{"status": "logged_out"};pc whoami/pc auth whoamiemit{"email": "...", "organization_id": "..."}from parsed JWT claims (raw token is never exposed);pc versionemits{"version": "...", "sha": "...", "built": "..."}.pc apiKey delete --jsonautomatically skips the interactive confirmation prompt, since agents cannot respond to stdin prompts.pc index deleteandpc collection deletewere refactored to extract arun*Cmdfunction (matching the pattern used by backup, namespace, and other commands), making them independently testable without going through Cobra.pc backup create,pc backup describe, andpc backup listwere switched frompcio.Printlntofmt.Printlndirectly, consistent with the new delete commands and the direction of SDK-700. This also unblocked testing those paths, sincepciois silenced byTestMainviatestutils.SilenceOutput().backup_test.gowas split into focused per-command test files (create_test.go,describe_test.go,list_test.go,delete_test.go), withbackup_test.goretaining only the shared mock andTestMain.testutils.CaptureStdoutwas added as a shared test helper (alongside the existingSilenceOutput) to avoid duplicating theos.Pipestdout-capture pattern across every package.SucceedsJSONtests capture actual stdout output and assert on it:assert.JSONEqfor our own delete envelope shapes (exact match, key-order independent);assert.Containsfor SDK-typed responses where the full serialization shape is owned externally.Type of Change
Test Plan
For testing, the specific focus should be around using the
--jsonflag with commands and validating the output.Key things to test:
Local testing output:
Note
Low Risk
Low risk additive CLI flags and output modes; main risk is minor behavior/output changes for scripts if they relied on exact stdout text or quiet-mode
pciobehavior.Overview
Adds
-j/--jsonoutput to the remaining delete/utility commands (api-key delete,backup delete,collection delete,index delete,index namespace delete,logout,whoami,version), emitting small structured payloads (e.g.,{"deleted":true,...}/{"status":"logged_out"}).Refactors
index deleteandcollection deleteto route through testablerun*helpers, and updates several backup commands’ JSON paths to print viafmt.Printlnso JSON reliably reaches stdout even whenpciois silenced.Splits backup command tests into per-command files and adds
testutils.CaptureStdoutto assert JSON output in tests.Written by Cursor Bugbot for commit 7cc662c. This will update automatically on new commits. Configure here.