Repository navigation
feat: output formats, JSON errors, exit codes and non-interactive behaviour - #5
Open
RogerCecilpot wants to merge 1 commit into
Open
RogerCecilpot wants to merge 1 commit into
RogerCecilpot wants to merge 1 commit into
Conversation
This was referenced Oct 25, 2026
…aviour
- --format table|tsv|json|yaml: a table at a terminal, header-less TSV when
piped; JSON/YAML print the API resource shape. --jq filters JSON with
gojq (strings print raw), --quiet prints IDs only.
- Colour only on a terminal, off with NO_COLOR, --no-color or TERM=dumb.
- Errors are printed and mapped to exit codes in one place
(cli.Execute). Under --format json or --jq, stderr carries one
{code,message,http_status,request_id,details,retryable} object.
- Exit codes 0-8 and 130 per the design spec; Cobra's own errors (unknown
command, bad flag, wrong args) are usage errors (exit 2).
- prompt.Confirm never prompts without a TTY and asks for --yes instead.
- --verbosity / DEVLYFT_DEBUG=1 logging through a redacting slog handler;
redact masks bearer tokens, JWTs, sensitive JSON fields, query/form
parameters and sensitive headers.
- Golden-file tests for every format and exit code.
Refs devlyft/devlyft#246
Co-Authored-By: Claude Opus 5.5 <[email protected]>
RogerCecilpot
force-pushed
the
feat/246-output-errors-exit-codes
branch
from
October 25, 2026 13:00
ab68d4d to
dd9fe8c
Compare
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.
Closes devlyft/devlyft#246. Stacked on #2; retarget to
mainonce that merges.Implements sections 6.3, 6.4 and 7 of the design spec.
What
internal/output):--format table|tsv|json|yaml. With no flag: aligned table at a terminal, header-less TSV when piped. JSON/YAML print the API resource shape (YAML viasigs.k8s.io/yaml, so field names match JSON).--jq(gojq, implies JSON; strings print raw likejq -r),--quietprints IDs. Commands hand the printer aResult{Data, Table, IDs}; a nilTablefalls back to YAML for single resources.internal/iostreams): TTY detection; colour only on a terminal and off withNO_COLOR,--no-colororTERM=dumb.internal/clierr): one error type with the stablecodestrings, HTTP-status mapping andretryable.cli.Executeis the only place errors are printed and mapped to exit codes. Human:Error:line, optionalHint:,Request ID:. Under--format json/--jq: one{code,message,http_status,request_id,details,retryable}object on stderr (all keys always present).internal/exitcode): 0, 1, 2, 3, 4, 5, 6, 7, 8, 130. Cobra's own errors (unknown command/flag, wrong number of args) are usage errors (exit 2), detected by whether the root's pre-run hook ran.prompt.Confirmnever prompts without a TTY on stdin and stderr; destructive commands get--yes(cmdutil.YesFlagUsage).--verbosity=debug|info|warning|error|noneorDEVLYFT_DEBUG=1, slog to stderr through a redacting handler.internal/redactmasks bearer tokens (incl. the WebSocketbearer, <token>subprotocol), JWTs, sensitive JSON fields (*token,secret,password,value, …), query/form params and sensitive headers. The HTTP layer (#236) should log through it.internal/cmdutil.Factorycarries IO, printer and logger to command packages.Tests
Golden files in
internal/cli/testdatacover every format, every error code (human and JSON), every exit code including 130, usage errors and confirmation (go test ./internal/cli -updateto regenerate). Unit tests for redaction (incl. the logger), the status→code→exit mapping and option validation.Decisions worth a look
Interrupted.and exits 130 with no JSON error object, even under--format json. The spec's code list has nointerruptedcode and I didn't want to invent one; the exit code is unambiguous. Easy to add if preferred.--quietcan't be combined with--format/--jq;--jqcan't be combined with--format yaml|table|tsv.unavailable(exit 1, retryable) rather thantimeout(exit 6), which the spec reserves for--wait/--timeout.sigs.k8s.io/yamlproperty); JSON keeps struct order.🤖 Generated with Claude Code