Skip to content

feat(cli): replace per-command --json with a global --output/-o - #121

Merged
jmgilman merged 1 commit into
masterfrom
feat/cli-ux-p1-output-flag
Jun 8, 2026
Merged

jmgilman merged 1 commit into
masterfrom
feat/cli-ux-p1-output-flag

Conversation

@jmgilman

@jmgilman jmgilman commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

P1 / PR-1.3 of the CLI UX overhaul. Replaces the scattered per-command --json flags with one global --output/-o.

⚠️ Breaking change (pre-1.0, intentional — locked decision #2)

  • --json and YACD_JSON are removed from list/info/wallet outright (no alias, no deprecation).
  • --output/-o (text|json, env YACD_OUTPUT) is the only machine-output toggle. Existing JSON byte shapes are unchanged.

What's here

  • Persistent --output -o (default text), bound to output/YACD_OUTPUT, validated once in PersistentPreRunE (added OutputFormat to RuntimeConfig).
  • Removed the three --json flag registrations + all viper.GetBool("json") reads in list.go/info.go/wallet.go; the JSON branches now gate on a new commandContext.outputJSON() helper.
  • formatText/formatJSON constants (the new enum handling crossed the goconst threshold).

Sequencing note (deviation from the 063 plan, intentional)

The 063 plan said PR-1.3 should route the JSON branch through cc.io.JSON(). That's impossible here — cc.io isn't built until PR-1.4 (the merged-context PR). So PR-1.3 reads the validated --output value via outputJSON() (viper-backed); PR-1.4 swaps these reads to cc.io.JSON() once the resolved ui.IO is threaded. The validated OutputFormat field lands now so PR-1.4 only re-points the read sites.

Testing

  • gofmt/go vet/go build clean; golangci-lint 0 issues; moon run root:check + moon run root:test (full envtest gate) green; git diff --check clean.
  • Existing --json invocations in list_test/info_test and the Chainsaw e2e (info … -o json) moved to -o json (byte-identical output — the frozen shapes are untouched).
  • New output_test.go: --json is now an unknown flag; YACD_OUTPUT is read + validated (a bogus value fails before the command runs); output defaults to text; outputJSON() is case-insensitive.

Part of the P1 foundation series (1.1 #119, 1.2 #120 merged → 1.3 → … → 1.6).

🤖 Generated with Claude Code

P1 foundation (PR-1.3) of the CLI UX overhaul. Add a persistent --output/-o
(text|json, env YACD_OUTPUT) as the single machine-output toggle, validated
once in PersistentPreRunE, and remove the per-command --json flags and all
YACD_JSON handling from list/info/wallet outright (pre-1.0 clean cut, no alias).

The JSON branches now gate on commandContext.outputJSON() (a viper-backed read
of the validated --output value); the frozen JSON byte shapes are unchanged.
PR-1.4 swaps these reads to cc.io.JSON() once the resolved ui.IO is threaded —
routing through cc.io now is impossible because cc.io does not exist until then.

Also introduce formatText/formatJSON constants to keep the new enum handling
under the goconst threshold.

Tests/Chainsaw: the --json invocations move to -o json (byte-identical output);
new coverage for --json being unknown, YACD_OUTPUT validation/precedence, the
output default, and the outputJSON helper.

BREAKING (pre-1.0, intentional): --json and YACD_JSON are removed; use
--output json / -o json (YACD_OUTPUT=json).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jmgilman
jmgilman merged commit dbfcc2e into master Jun 8, 2026
12 checks passed
@jmgilman
jmgilman deleted the feat/cli-ux-p1-output-flag branch June 8, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant