创建接受两组不同参数的点击命令
Creating a click command that accepts two different sets of arguments
通过 python 包点击我有遗留代码,在命令行上看起来如下:
toolName toolCommand 参数
我已经更新了命令的遗留代码,现在可以接受三个参数:
toolName toolCommand arugment1 argument2 argument3
虽然新代码符合新标准,但遗留代码仍然有价值,可能 used/needed。有谁知道是否可以通过点击包管理器允许用户决定使用哪些参数(旧标准或新标准)来满足他们的需求?
我最终使用点击标记来解决这个问题。
如果存在遗留代码的标志,那么它将 运行 代码视为遗留代码。如果存在用于现代化代码的标志,它将 运行 最新版本的代码。
编辑:更好的是你可以把它分成子命令:
@click.group(invoke_without_command=False)
@click.pass_context
def cli(ctx):
pass
@cli.command('subcommand_1', short_help='Function does x thing.')
#Arguments/Paramaters
.............
............
............
def subcommand_1:
#Code
#End of funcction
# write another subcommand
# write arguments/options
# define sub command
调用命令时你会做:
工具名称command_name子command_namearguments/options
通过 python 包点击我有遗留代码,在命令行上看起来如下:
toolName toolCommand 参数
我已经更新了命令的遗留代码,现在可以接受三个参数:
toolName toolCommand arugment1 argument2 argument3
虽然新代码符合新标准,但遗留代码仍然有价值,可能 used/needed。有谁知道是否可以通过点击包管理器允许用户决定使用哪些参数(旧标准或新标准)来满足他们的需求?
我最终使用点击标记来解决这个问题。
如果存在遗留代码的标志,那么它将 运行 代码视为遗留代码。如果存在用于现代化代码的标志,它将 运行 最新版本的代码。
编辑:更好的是你可以把它分成子命令:
@click.group(invoke_without_command=False)
@click.pass_context
def cli(ctx):
pass
@cli.command('subcommand_1', short_help='Function does x thing.')
#Arguments/Paramaters
.............
............
............
def subcommand_1:
#Code
#End of funcction
# write another subcommand
# write arguments/options
# define sub command
调用命令时你会做:
工具名称command_name子command_namearguments/options