def get_command(self, ctx, cmd_name):
"""This function checks whether ``cmd_name`` can be matched to one
of the registered commands.
Parameters
----------
cmd_name : str
Input string from the command line.
Returns
-------
matched_command : click.Command
Returns matched command
"""
matched_command = click.Group.get_command(self, ctx, cmd_name)
if matched_command is not None:
return matched_command
matches = [x for x in self.list_commands(ctx)
if x.startswith(cmd_name)]
if not matches:
return None
elif len(matches) == 1:
matched_command = click.Group.get_command(self, ctx, matches[0])
return matched_command
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
评论列表
文章目录