单击不会让我传递多个文件,尽管它应该是可能的

Click wouldn't let me pass multiple files, although it should be possible

我正在尝试对多个文件使用点击。例如:

@cli.command("test")
@click.argument('input', type=click.File('rb'))
def test(input):
    with click.progressbar(input, label='READING') as bar:
        for x in bar:
            pass

当我做这样的事情时:

script test ~/ololo/*

我得到:

Error: Got unexpected extra arguments ( ... listing all files in folder ...)

您需要使用 nargs 参数。如果设置为 -1,则接受无限数量的参数:http://click.pocoo.org/6/arguments/#variadic-arguments

@cli.command("test")
@click.argument('input', nargs=-1, type=click.File('rb'))
def test(input):
    with click.progressbar(input, label='READING') as bar:
        for x in bar:
            pass