Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not override the command order of a custom group's list_commands() #33

Merged
merged 3 commits into from
Aug 15, 2024
Merged

fix: Do not override the command order of a custom group's list_commands() #33

merged 3 commits into from
Aug 15, 2024

Conversation

jpmckinney
Copy link
Contributor

@jpmckinney jpmckinney commented Aug 15, 2024

list_commands() is one of "The most common methods to override" in Click. CLIs with many commands typically sort the commands in a logical order (rather than an alphabetical order), to make it easier for users to understand and remember sequence, dependency, etc.

This same behavior is available in Typer. For example, to list commands in the same order in which they are defined and registered:

import typer
import typer.cli

class OrderedGroup(typer.cli.TyperCLIGroup):
    def list_commands(self, ctx: click.Context) -> list[str]:
        self.maybe_add_run(ctx)
        return list(self.commands)


app = typer.Typer(cls=OrderedGroup)

sphinxcontrib-typer doesn't respect the established order, and instead re-sorts by name.

@bckohan bckohan self-assigned this Aug 15, 2024
@bckohan bckohan self-requested a review August 15, 2024 17:58
@bckohan bckohan merged commit 40e6cbb into sphinx-contrib:main Aug 15, 2024
17 checks passed
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.07%. Comparing base (48a55f4) to head (b2566b2).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #33   +/-   ##
=======================================
  Coverage   89.07%   89.07%           
=======================================
  Files           1        1           
  Lines         366      366           
=======================================
  Hits          326      326           
  Misses         40       40           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jpmckinney jpmckinney deleted the fix-list-commands-order branch August 16, 2024 00:33
@jpmckinney
Copy link
Contributor Author

Sweet! Thank you!

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