Commit ce4c270a authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME
Browse files

[click_helper] Implement AliasedGroup.

Implements get_command used for commands aliasing. Use prefix aliasing.
parent 8cc48236
......@@ -10,6 +10,7 @@ try:
except NameError:
basestring = str
def verbosity_option(**kwargs):
"""Adds a -v/--verbose option to a click command.
......@@ -37,3 +38,18 @@ def verbosity_option(**kwargs):
"--verbose option as often as desired (e.g. '-vvv' for debug).",
callback=callback, **kwargs)(f)
return custom_verbosity_option
class AliasedGroup(click.Group):
def get_command(self, ctx, cmd_name):
rv = click.Group.get_command(self, ctx, cmd_name)
if rv is not None:
return rv
matches = [x for x in self.list_commands(ctx)
if x.startswith(cmd_name)]
if not matches:
return None
elif len(matches) == 1:
return click.Group.get_command(self, ctx, matches[0])'Too many matches: %s' % ', '.join(sorted(matches)))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment