fix(cli): root usage/error/format hygiene (TASK-2031, BUG-2032)#893
Merged
Conversation
…date --format TASK-2031 + BUG-2032 (PLAN-1985). SilenceUsage + FlagErrorFunc keeps flag-error help; GetItem/UpdateItem/DeleteItem wrap not_found with ref+workspace; PersistentPreRunE rejects invalid --format; honest markdown advertising.
…e type Team-lead P2: itemNotFoundError changed the concrete error type, so direct err.(*cli.APIError) assertions (which do not unwrap) stopped matching not_found — notably bulk-update's per-row code capture (cmd_item.go:2043), dropping code:"not_found" from the JSON envelope. Return a fresh *APIError (same Code/Details, enriched Message) instead of a wrapper type; APIError.Error() returns Message so the clean one-line message is unchanged. Both err.(*APIError) and errors.As now match. Test adds a direct-assertion + Details-passthrough lock-in.
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Root-command hygiene for the
padCLI — TASK-2031 + BUG-2032 (PLAN-1985). Two tiny, relatednewRootCmd()/client edits bundled into one PR.TASK-2031a — silence the usage dump on runtime errors
SilenceUsage: trueon the root command so runtime failures (item not found, network errors) print a clean one-line error with no Cobra usage block. ASetFlagErrorFuncreprints usage for the flag-parse path only (that path genuinely wants it), printing just the usage block and letting Cobra print the singleError: …line — so the message isn't duplicated.TASK-2031b — echo the failing input on item-not-found
GetItem/UpdateItem/DeleteItemnow wrap a barenot_foundAPIErrorwith the ref + workspace:item TASK-999999 not found in workspace docappinstead of the context-freeItem not found. The wrapper (wrapItemNotFound+itemNotFoundError) keeps the clean message and unwraps to the original*APIErrorsoerrors.As/ structured callers still seeCode/Details(Codex round-1 fix). Non-not_founderrors pass through unchanged.BUG-2032a — validate the
--formatenumPersistentPreRunEon root rejects any--formatoutsidetable|json|markdowninstead of silently rendering a table. Thehelpcommand binds its own local--format(text/md/json/llm), which shadows the persistent flag, sopad help … --format mdleaves the persistentformatFlagat itstabledefault and still passes.--version/--helpshort-circuit beforePersistentPreRunE, so they're unaffected.BUG-2032b — honest markdown advertising
Global
--formathelp changed fromoutput format: table, json, markdowntooutput format: table, json (markdown on select commands, e.g. item show, project changelog)— markdown is implemented on ~3 of 84 commands.Files changed
cmd/pad/main.go—SilenceUsage,SetFlagErrorFunc,PersistentPreRunE, honest--formathelpinternal/cli/client.go—wrapItemNotFound+itemNotFoundError(Unwraps to*APIError);GetItem/UpdateItem/DeleteItemwrapnot_foundcmd/pad/format_flag_test.go(new) —--formatvalidation: wiring (negative Execute) + valid/invalid valuesinternal/cli/item_notfound_test.go(new) — httptest: not-found wrapping across all three methods, error-chainerrors.Asassertion, and pass-through of non-not_founderrorsGate results
go build ./...— PASSgo vet ./...— PASSmake lint(golangci-lint v2.11.4) — PASS (0 issues)go test ./internal/cli/... ./cmd/pad/...— PASSCodex review
CLEAN (2 rounds). Round 1 flagged that the
not_foundwrap discarded the*APIError(losingCode/Detailsforerrors.As); fixed withitemNotFoundError.Unwrap()(a plain%wwould have appended: Item not foundand broken the clean-message acceptance). Round 2: CLEAN. ConfirmedPersistentPreRunEdoes not break the help command's--format,--version, or--help, and the FlagErrorFunc/SilenceUsage combo is correct.Empirical before/after (verified against the live server)
item show TASK-999999Error: Item not found+ full usage blockError: item TASK-999999 not found in workspace docapp(no usage)item list --format bogusError: invalid --format "bogus": must be one of table, json, markdown(no usage)item list --bogusflagError: unknown flag: --bogusflag(single error, helpful)help item show --format md--versionpad version devpad version dev(unchanged)