Skip to content

Commit 635ef55

Browse files
committed
Add UnderscoreCommandGroup
1 parent 8c23da2 commit 635ef55

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

consolekit/commands.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@
7474
from consolekit.utils import TerminalRenderer
7575

7676
__all__ = (
77+
"ContextInheritingGroup",
7778
"MarkdownHelpCommand",
7879
"MarkdownHelpGroup",
7980
"MarkdownHelpMixin",
8081
"RawHelpCommand",
8182
"RawHelpGroup",
8283
"RawHelpMixin",
8384
"SuggestionGroup",
84-
"ContextInheritingGroup",
85+
"UnderscoreCommandGroup",
8586
)
8687

8788
_argument = Plural("argument", "arguments")
@@ -431,3 +432,14 @@ def resolve_command(
431432
# I think typeshed is wrong.
432433
# https://github.com/python/typeshed/blob/484c014665cdf071b292dd9630f207c03e111895/third_party/2and3/click/core.pyi#L171
433434
return cmd_name, cmd, args[1:] # type: ignore[return-value]
435+
436+
437+
class UnderscoreCommandGroup(SuggestionGroup):
438+
"""
439+
Modified :class:`~.SuggestionGroup` that allows command names to be given with underscores (matching the Python function names) as well as with hyphens.
440+
441+
.. versionadded:: 1.14.0
442+
"""
443+
444+
def get_command(self, ctx: click.Context, cmd_name: str) -> Optional[click.Command]: # noqa: D102
445+
return self.commands.get(cmd_name.replace('_', '-'))

0 commit comments

Comments
 (0)