提问人:Dennis Jung 提问时间:3/12/2023 更新时间:3/12/2023 访问量:15
指示 python 单击的临时命令
Indicate temporary command for python click
问:
有没有办法指示临时命令(通过文件或 API 读取)?
例如,下面是一个示例命令
$ my-command
Usage: my-command [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
create Create item
delete Delete item
get Get item
当我跑步时
$ my-command google.com open
我想让它 google.com 页面打开。但目前它返回 ,正如预期的那样。No such command 'google.com'
我试过使用模式,Command Aliases
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])
ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
def resolve_command(self, ctx, args):
# always return the full command name
_, cmd, args = super().resolve_command(ctx, args)
return cmd.name, cmd, args
但是我无法获得参数数据。get_command
这有什么有用的模式吗?
答: 暂无答案
评论