Skip to content

fix(cli): skip hidden commands in typer utils docs output - #1970

Closed
yunaremaia wants to merge 2 commits into
fastapi:masterfrom
yunaremaia:fix/docs-skip-hidden-commands
Closed

yunaremaia wants to merge 2 commits into
fastapi:masterfrom
yunaremaia:fix/docs-skip-hidden-commands

Conversation

@yunaremaia

Copy link
Copy Markdown

Summary

typer utils docs publishes commands marked hidden=True, even though every other help path in Typer hides them.

--help skips hidden commands (both in Rich and plain mode), and rich_format_help() also filters them out (if command and not command.hidden in typer/rich_utils.py). The Markdown generator in typer/cli.py did 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 docs currently emits:

**Commands**:

* `visible`: Visible command.
* `hidden-decorated`: Hidden via @app.command(hidden=True).
* `hidden-var`: Hidden via app.command(name,...
* `hidden-subgroup`

## `visible`
...

## `hidden-decorated`

Hidden via @app.command(hidden=True).

**Usage**:

    $ hidden-decorated [OPTIONS]

...

## `hidden-subgroup`

**Usage**:

    $ hidden-subgroup [OPTIONS]

While the app's own help (python -m typer tests.assets.hidden_commands --help) shows only visible.

Root cause

get_docs_for_click() in typer/cli.py built the command list with a bare group.list_commands(ctx) and then used that list for both the **Commands** index and the recursive per-command sections, without consulting Command.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:

commands = [
    command
    for command in group.list_commands(ctx)
    if (command_obj := group.get_command(ctx, command)) is not None
    and not command_obj.hidden
]

After the fix the generated docs contain only the **Commands** entry and section for visible.

Verification

New test tests/test_cli/test_doc_hidden.py calls get_docs_for_click() on tests.assets.hidden_commands and asserts the visible command is documented while the hidden ones are not.

  • RED: reverting only typer/cli.py makes the new test fail (hidden-decorated still present in the output) while the pre-existing tests/test_hidden.py still passes.
  • GREEN: with the fix, pytest tests/test_cli tests/test_hidden.py tests/test_others.py tests/test_core.py gives 124 passed, 1 skipped.
  • Manual end-to-end: python -m typer tests.assets.hidden_commands utils docs now emits only the visible command.
  • ruff check and ruff format --check are 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.

@yunaremaia

Copy link
Copy Markdown
Author

Thanks for the fix! All checks are green and the PR is mergeable. Ready for review.

@yunaremaia

Copy link
Copy Markdown
Author

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 typer utils docs output. Would appreciate a look when you have a moment. Thanks!

@svlandeg svlandeg 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.

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.

@svlandeg
svlandeg marked this pull request as draft October 11, 2026 18:23
@yunaremaia
yunaremaia marked this pull request as ready for review October 22, 2026 18:50
@yunaremaia

Copy link
Copy Markdown
Author

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 typer utils docs output — happy to link the PR to one if you point me at it. CI is running on the updated branch.

@yunaremaia yunaremaia closed this by deleting the head repository Oct 23, 2026
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.

3 participants