Skip to content

feat(cli): add --json flag for machine-readable output across all commands#35

Merged
EndersonPro merged 1 commit intomainfrom
feature/stdout-json
Apr 23, 2026
Merged

feat(cli): add --json flag for machine-readable output across all commands#35
EndersonPro merged 1 commit intomainfrom
feature/stdout-json

Conversation

@EndersonPro
Copy link
Copy Markdown
Owner

@EndersonPro EndersonPro commented Apr 23, 2026

Summary

Add --json flag to all CLI commands to enable machine-readable JSON output for integration with scripts and other tools.

Changes

New Flag: --json

All commands now support --json to output results as formatted JSON:

Command JSON Output
flutree version --json {"version": "1.0.0"}
flutree list --json Array of worktree objects
flutree config set/get --json {"key": "...", "value": "..."}
flutree create --json CreateResult object
flutree complete --json CompleteResult object
flutree pubget --json PubGetResult object
flutree clean --json CleanResult object
flutree add-repo --json AddRepoResult object
flutree update --json UpdateResult object

Error Handling

When --json is passed, errors are also returned as JSON:

{
  "error": {
    "category": "input",
    "code": 2,
    "message": "Missing worktree name.",
    "hint": "Usage: flutree create <name> [options]"
  }
}

Files Modified

  • cmd/flutree/main.go - Added --json flag to all commands + help documentation
  • internal/domain/types.go - Added JSON struct tags to all result types
  • internal/runtime/runtime.go - Added ExitOnErrorJSON() for JSON error output
  • integration/cli_contract_test.go - Added tests for JSON output

Backwards Compatibility

✅ All existing behavior preserved - without --json, commands output exactly as before.

Testing

# All 188 tests pass
go test ./... -short

@EndersonPro EndersonPro self-assigned this Apr 23, 2026
@EndersonPro EndersonPro reopened this Apr 23, 2026
@EndersonPro EndersonPro changed the title feat(cli): add --json flag for JSON output in commands and error hand… feat(cli): add --json flag for machine-readable output across all commands Apr 23, 2026
@EndersonPro EndersonPro merged commit 6b14220 into main Apr 23, 2026
2 checks passed
@EndersonPro EndersonPro deleted the feature/stdout-json branch April 23, 2026 14:55
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