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

1

6

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 ...)
Bacchius answered 13/1, 2016 at 9:33 Comment(0)
C
9

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
Chuchuah answered 13/1, 2016 at 10:8 Comment(1)
Thank you, it should definitely be documented in the section about working with files. Gonna leave an issue later. Have a nice day.Bacchius

© 2022 - 2024 — McMap. All rights reserved.