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

若如初见. 提交于 2019-12-23 10:07:19

问题


I'm trying to use click for multiple files. For example:

@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

When I do something like this:

script test ~/ololo/*

I get:

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

回答1:


You need to use nargs parameter. If it is set to -1, then an unlimited number of arguments is accepted: 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


来源:https://stackoverflow.com/questions/34762947/click-wouldnt-let-me-pass-multiple-files-although-it-should-be-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!