Skip to content

Comments

fix: passthrough --json/--jq/--template flags in all gh subcommands#196

Open
shadowofdoom wants to merge 1 commit intortk-ai:masterfrom
shadowofdoom:fix/gh-view-passthrough-json
Open

fix: passthrough --json/--jq/--template flags in all gh subcommands#196
shadowofdoom wants to merge 1 commit intortk-ai:masterfrom
shadowofdoom:fix/gh-view-passthrough-json

Conversation

@shadowofdoom
Copy link
Contributor

Summary

  • gh pr view --json fields failed with Unknown JSON field: "--json" because view_pr() treated --json as the PR identifier
  • The v0.21.1 fix (fix: gh run view drops --log-failed, --log, --json flags #159) only covered gh run view via should_passthrough_run_view()
  • This generalizes the fix with has_output_format_flags() and applies it to all handlers that hardcode --json: list_prs, view_pr, pr_status, list_issues, view_issue, list_runs, and run_repo
  • Also fixes view_pr to handle omitted PR number (gh defaults to current branch)

Reproduction

rtk gh pr view --json number,title,state
# Before: Unknown JSON field: "--json"
# After: passes through to gh correctly

Test plan

  • All 383 tests pass (5 new tests for has_output_format_flags)
  • rtk gh pr view --json number,title,state passes through correctly
  • rtk gh pr list still uses RTK's compressed output
  • rtk gh pr view <number> still uses RTK's compressed output

🤖 Generated with Claude Code

view_pr() assumed args[0] was always a PR number, so
`gh pr view --json fields` treated "--json" as the PR identifier
and appended its own --json, causing `Unknown JSON field: "--json"`.

The v0.21.1 fix (should_passthrough_run_view) only covered
`gh run view`. This generalizes it with has_output_format_flags()
and applies it to all handlers that hardcode --json fields:
list_prs, view_pr, pr_status, list_issues, view_issue,
list_runs, and run_repo.

Also fixes view_pr to handle omitted PR number (gh defaults to
current branch).

Closes rtk-ai#159 (broader fix)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Collaborator

Tested locally on the branch — LGTM, approve.

All 383 tests pass. Manual testing confirms:

  • gh pr view --json, gh pr list --json --jq, gh issue list --json --jq, gh repo view --json, gh pr status --json, gh run list --json --jq — all passthrough correctly with raw JSON output
  • gh pr list, gh pr view 196, gh issue view 228 — RTK filtering still works, no regression

Minor nits (non-blocking):

  • cargo fmt flags 2 formatting issues in tests
  • Consider dropping -t/-q short flags from has_output_format_flags() — they could cause false positives if other gh subcommands reuse those short flags for something else. --json, --jq,
    --template are sufficient and unambiguous.

@pszymkowiak
Copy link
Collaborator

please review conflict to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants