Reject --comments with --json by BagToad · Pull Request #14215 · cli/cli · GitHub
Skip to content

Reject --comments with --json - #14215

Merged
BagToad merged 1 commit into
trunkfrom
bagtoad/fix-issue-comments-json
Aug 27, 2026
Merged

Reject --comments with --json#14215
BagToad merged 1 commit into
trunkfrom
bagtoad/fix-issue-comments-json

Conversation

@BagToad

@BagToad BagToad commented Aug 20, 2026

Copy link
Copy Markdown
Member

Fixes #14214

Description

Passing --comments with --json currently succeeds, but JSON field selection takes precedence and silently ignores --comments.

Reject this combination in the issue, pull request, and discussion view commands. Each command now returns "specify only one of --comments or --json" instead.

How did you test this change?

Given a built bin/gh and an issue
When I run ./bin/gh issue view 14214 --repo cli/cli --comments --json number
Then the command exits with "specify only one of --comments or --json" before making an API request.

Given the string-valued search qualifier
When I run ./bin/gh search issues --repo cli/cli --comments 5 --json number --limit 1 and the equivalent search prs command
Then both commands return JSON results.

Key points

Each view command validates the modes it owns. Shared JSON flag handling remains unaware of --comments, leaving string-valued search qualifiers compatible with JSON output.

Notes for reviewers

Start with the three NewCmdView checks and their constructor tests. The expected behavior was confirmed in #14214 (comment).

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @BagToad will read and reply directly.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

@BagToad
BagToad requested a review from a team as a code owner August 20, 2026 23:11
@BagToad
BagToad requested review from babakks and a balanced review from Copilot August 20, 2026 23:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Rejects incompatible --comments and --json view-mode flags through shared JSON validation.

Changes:

  • Adds validation for the conflicting flags.
  • Adds unit coverage for the validation error.
Show a summary per file
File Description
pkg/cmdutil/json_flags.go Adds shared conflict validation.
pkg/cmdutil/json_flags_test.go Tests the new error path.

Review details

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread pkg/cmdutil/json_flags.go Outdated
@BagToad
BagToad force-pushed the bagtoad/fix-issue-comments-json branch from 67b3e0d to 2f6ec39 Compare August 20, 2026 23:26

@babakks babakks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but I'd rather do this check in the command checks rather than here.

@BagToad

BagToad commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

Approved, but I'd rather do this check in the command checks rather than here.

@babakks I'll hold off on merging this because I want to check in on how strongly you feel on that - I wasn't sure on the direction here so I opted to just do them where the other mutual exclusion checks for --json already are. For that reason, I guess I mildly prefer this direction just based on aligning with the other checks.

@williammartin

Copy link
Copy Markdown
Member

I feel fairly strongly that the JSON flag handling shouldn't know about other arbitrary flags. Some of the ones in the same design space I understand (e.g. template) but web is suspicious and comments even more so.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@BagToad
BagToad force-pushed the bagtoad/fix-issue-comments-json branch from 2f6ec39 to a18c1bc Compare August 25, 2026 17:56
@BagToad

BagToad commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

@williammartin @babakks this has been rewritten

@BagToad

BagToad commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

@BagToad
BagToad merged commit 7ca1a75 into trunk Aug 27, 2026
18 checks passed
@BagToad
BagToad deleted the bagtoad/fix-issue-comments-json branch August 27, 2026 04:42
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.

issue view --comments --json silently ignores --comments

4 participants