Skip to content

Show help items in order of definition, not alphabetically #933

@tiangolo

Description

@tiangolo

Privileged issue

  • I'm @tiangolo or he asked me directly to create an issue here.

Issue Content

Show help items in order of definition, not alphabetically

For example:

import typer

app = typer.Typer()


@app.command()
def first(word: str | None = None):
    """
    First declared command should show up first.
    """
    print(f"first {word}")


@app.command()
def after(word: str | None = None):
    """
    Last declared command should show up last, not alphabetically.
    """
    print(f"after {word}")

This is the current output:

$ typer demo.py run --help
                                                                            
 Usage: typer [PATH_OR_MODULE] run [OPTIONS] COMMAND [ARGS]...              
                                                                            
 Run the provided Typer app.                                                
                                                                            
╭─ Options ────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                              │
╰──────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────╮
│ after   Last declared command should show up last, not alphabetically.   │
│ first   First declared command should show up first.                     │
╰──────────────────────────────────────────────────────────────────────────╯

This is the ideal output:

$ typer demo.py run --help
                                                                            
 Usage: typer [PATH_OR_MODULE] run [OPTIONS] COMMAND [ARGS]...              
                                                                            
 Run the provided Typer app.                                                
                                                                            
╭─ Options ────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                              │
╰──────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────╮
│ first   First declared command should show up first.                     │
│ after   Last declared command should show up last, not alphabetically.   │
╰──────────────────────────────────────────────────────────────────────────╯

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature, enhancement or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions