Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/assets/cli/hidden_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import typer

internal_app = typer.Typer()


@internal_app.command()
def rebuild():
"""
Rebuild the index
"""


app = typer.Typer()
app.add_typer(internal_app, name="internal", hidden=True)


@app.command()
def public():
"""
Public command
"""


@app.command(hidden=True)
def secret():
"""
Secret command
"""
24 changes: 24 additions & 0 deletions tests/test_cli/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ def test_doc_output(tmp_path: Path):
assert "Docs saved to:" in result.stdout


def test_doc_hidden_commands():
result = subprocess.run(
[
sys.executable,
"-m",
"coverage",
"run",
"-m",
"typer",
"tests.assets.cli.hidden_app",
"utils",
"docs",
"--name",
"hiddenapp",
],
capture_output=True,
encoding="utf-8",
)
assert "`hiddenapp public`" in result.stdout
assert "secret" not in result.stdout
assert "internal" not in result.stdout
assert "rebuild" not in result.stdout


def test_doc_title_output(tmp_path: Path):
out_file: Path = tmp_path / "out.md"
result = subprocess.run(
Expand Down
15 changes: 8 additions & 7 deletions typer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,22 @@ def get_docs_for_click(
docs += f"{obj.epilog}\n\n"
if isinstance(obj, TyperGroup):
group = obj
commands = group.list_commands(ctx)
commands = []
for command in group.list_commands(ctx):
command_obj = group.get_command(ctx, command)
assert command_obj
if not command_obj.hidden:
commands.append(command_obj)
if commands:
docs += "**Commands**:\n\n"
for command in commands:
command_obj = group.get_command(ctx, command)
assert command_obj
for command_obj in commands:
docs += f"* `{command_obj.name}`"
command_help = command_obj.get_short_help_str()
if command_help:
docs += f": {_parse_html(to_parse, command_help)}"
docs += "\n"
docs += "\n"
for command in commands:
command_obj = group.get_command(ctx, command)
assert command_obj
for command_obj in commands:
use_prefix = ""
if command_name:
use_prefix += f"{command_name}"
Expand Down
Loading