Skip to content

feat: add --output json global flag for machine-readable output#32

Closed
aaearon wants to merge 1 commit intofeat/tty-detectionfrom
feat/output-json
Closed

feat: add --output json global flag for machine-readable output#32
aaearon wants to merge 1 commit intofeat/tty-detectionfrom
feat/output-json

Conversation

@aaearon
Copy link
Owner

@aaearon aaearon commented Feb 21, 2026

Summary

  • Adds --output/-o persistent flag on root command accepting text (default) or json
  • JSON mode forces non-interactive by setting IsTerminalFunc to return false
  • All commands now support JSON output: root elevation, env, status, revoke, favorites list
  • Creates cmd/output.go (helpers), cmd/output_types.go (JSON structs)
  • Adds json:"..." struct tags to config.Favorite alongside existing yaml:"..." tags

Motivation

LLM agents and scripts need machine-readable output to parse elevation results, session lists, and credentials without scraping human-readable text.

Depends on

Test plan

  • TestIsJSONOutput — table test for format detection
  • TestWriteJSON — verifies valid indented JSON output
  • TestOutputFlagValidation — validates text/json accepted, xml rejected
  • TestRootElevate_JSONOutput — Azure cloud, AWS with credentials, group elevation JSON
  • TestEnvCommand_JSONOutput — AWS credentials as JSON
  • TestStatusCommand_JSONOutput — not authenticated and with sessions
  • TestRevokeCommand_JSONOutput — revocation results as JSON array
  • TestFavoritesList_JSONOutput — cloud and group favorites as JSON array
  • All existing tests pass (make test)
  • Lint clean (make lint)

Add persistent --output/-o flag (text/json) validated in PersistentPreRunE.
JSON mode forces non-interactive by setting IsTerminalFunc to false.

All commands now support JSON output:
- Root elevation: cloudElevationOutput / groupElevationJSON
- grant env: awsCredentialOutput
- grant status: statusOutput with sessions array
- grant revoke: []revocationOutput
- grant favorites list: []favoriteOutput

Add json struct tags to config.Favorite alongside yaml tags.
@aaearon aaearon deleted the branch feat/tty-detection February 21, 2026 08:31
@aaearon aaearon closed this Feb 21, 2026
@aaearon aaearon deleted the feat/output-json branch February 21, 2026 08:32
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