Repository navigation
fix(cli): skip hidden commands in typer utils docs output - #1970
yunaremaia wants to merge 2 commits into
Conversation
|
Thanks for the fix! All checks are green and the PR is mergeable. Ready for review. |
|
Hi! This PR is ready for review. All checks are passing (100% coverage on the changed path) and the change is minimal — it just skips hidden commands in |
svlandeg
left a comment
There was a problem hiding this comment.
Putting this PR in draft as there are merge conflicts.
@yunaremaia : please disclose AI usage and link the relevant discussion thread as per the contribution guidelines.
|
Branch updated with the latest master (the previous conflict is resolved) and marked ready for review. I searched the tracker and did not find an existing discussion thread for hidden commands leaking into |
Summary
typer utils docspublishes commands markedhidden=True, even though every other help path in Typer hides them.--helpskips hidden commands (both in Rich and plain mode), andrich_format_help()also filters them out (if command and not command.hiddenintyper/rich_utils.py). The Markdown generator intyper/cli.pydid not, so internal or experimental subcommands intended to stay out of sight ended up fully documented — including their own nested sections, which is how private surface area leaks into a published README.Problem
Using the existing test asset
tests/assets/hidden_commands.py(a visible command, two hidden commands, and a hidden sub-typer),typer tests.assets.hidden_commands utils docscurrently emits:While the app's own help (
python -m typer tests.assets.hidden_commands --help) shows onlyvisible.Root cause
get_docs_for_click()intyper/cli.pybuilt the command list with a baregroup.list_commands(ctx)and then used that list for both the**Commands**index and the recursive per-command sections, without consultingCommand.hidden.Fix
Filter the list once, at the single place every consumer of it reads from, so both the index and the recursion are covered:
After the fix the generated docs contain only the
**Commands**entry and section forvisible.Verification
New test
tests/test_cli/test_doc_hidden.pycallsget_docs_for_click()ontests.assets.hidden_commandsand asserts the visible command is documented while the hidden ones are not.typer/cli.pymakes the new test fail (hidden-decoratedstill present in the output) while the pre-existingtests/test_hidden.pystill passes.pytest tests/test_cli tests/test_hidden.py tests/test_others.py tests/test_core.pygives 124 passed, 1 skipped.python -m typer tests.assets.hidden_commands utils docsnow emits only the visible command.ruff checkandruff format --checkare clean on both changed files.The full local suite was not run (VPS memory budget); CI is the verification.
Notes
This is a docs-only path, so the diff is confined to
typer/cli.py; no runtime behavior changes.