Skip to content

CLI: populate List with the * wildcard (like argparse nargs='+') #550

Closed
@PaulLerner

Description

@PaulLerner

🚀 Feature request

Motivation

def main(foo: List[str] = None):
    pass
    
if __name__ == "__main__":
    CLI(main)

Currently, to pass several arguments to a List, the syntax is quite difficult, you need to do something like

python jsonargparse_demo.py --foo+=ab --foo+=ac 

Pitch

A great thing about argparse is that you can add nargs='+'

def main(foo: List[str]):
    pass


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('foo', type=str, nargs='+')
    main(**vars(parser.parse_args()))

so you can call it like

python jsonargparse_demo.py a*

and match all files starting with "a"

Alternatives

I guess you can already do this using the ArgumentParser from jsonargparse but I like CLI so much, it's really convenient otherwise, thanks again for the great library btw!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions