-
-
Notifications
You must be signed in to change notification settings - Fork 783
Closed
Labels
Description
I'm not familiar with the internals of typer
and whether this is feasible, but it would be nice if it were possible to implement a command like the following:
from typing import Optional, List
import typer
app = typer.Typer()
@app.command()
def main(first_list: List[str], option: bool = False, second_list: List[str] = ()):
print(first_list, second_list)
Where the expected behavior is:
$ python main.py a b c --option d e f
('a', 'b', 'c') ('d', 'e', 'f')
$ python main.py a b c d e f --option
('a', 'b', 'c', 'd', 'e', 'f') ()
$ python main.py a b c d e f
('a', 'b', 'c', 'd', 'e', 'f') ()
However the actual behavior in this case does not adhere to the above:
$ python main.py a b c --option d e f
('a', 'b', 'c', 'd', 'e', 'f') True ()
This can presently be achieved in argparse
quite concisely:
import argparse
def main():
cli = argparse.ArgumentParser()
cli.add_argument(
"first_list", nargs="*", type=str,
)
cli.add_argument(
"--option", nargs="*", type=str, default=[],
)
args = cli.parse_args()
print(args.first_list, args.option)
alsimoneau, tekumara, riyadparvez, noaonoszko and ankostis