Skip to content

feat(cli): add --json flag to flask routes command#6003

Closed
sahilmalhotra1987 wants to merge 1 commit intopallets:mainfrom
sahilmalhotra1987:feat/routes-json-flag
Closed

feat(cli): add --json flag to flask routes command#6003
sahilmalhotra1987 wants to merge 1 commit intopallets:mainfrom
sahilmalhotra1987:feat/routes-json-flag

Conversation

@sahilmalhotra1987
Copy link
Copy Markdown

Summary

  • Adds a --json flag to flask routes that outputs the route table as a JSON array instead of the text table
  • Each entry has endpoint, methods (sorted list), and rule; subdomain apps also emit subdomain, host-matching apps emit host
  • HEAD and OPTIONS are filtered unless --all-methods is also passed; empty apps produce []
  • The --sort flag is honoured in JSON mode (match preserves natural iter_rules() order)
  • Fully backwards-compatible — all existing flask routes invocations are unaffected

Test plan

  • test_json_output — basic shape: keys endpoint, methods, rule present; methods is a list
  • test_json_no_routes — empty app returns []
  • test_json_excludes_head_options_by_default — HEAD/OPTIONS absent without --all-methods
  • test_json_all_methods — HEAD/OPTIONS present with --all-methods
  • test_json_with_subdomainsubdomain key present and correct value
  • test_json_with_host_matchinghost key present and correct value
  • test_json_sort (parametrized) — endpoint and rule sort keys produce sorted output
  • test_json_sort_match_preserves_iter_rules_order--sort match preserves natural route order

🤖 Generated with Claude Code

Adds a machine-readable output mode to `flask routes`. When --json is
passed, the route table is emitted as a JSON array instead of the text
table. Each entry has `endpoint`, `methods` (sorted list), and `rule`;
subdomain apps also emit `subdomain`, host-matching apps emit `host`.
HEAD/OPTIONS are filtered unless --all-methods is also passed. Empty
apps produce `[]`. The --sort flag is honoured in JSON mode.

Backwards compatible: the flag is optional and all existing invocations
of `flask routes` are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ThiefMaster
Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

No thanks. If we wanted AI-generated code, we could just use these tools ourselves.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants