typed-argparse / typed-argparse

💡 write type-safe and elegant CLIs with a clear separation of concerns.
https://typed-argparse.github.io/typed-argparse/
MIT License
27 stars 6 forks source link

Documentation: Non optional positional list #39

Closed Roang-zero1 closed 1 year ago

Roang-zero1 commented 1 year ago

It is currently possible to define non optional lists by using nargs="+", but the documentation does not mention this. As this is especially interesting for positional arguments I would propose to add it to that section of the documentation

For example:

from pathlib import Path

import typed_argparse as tap

class Args(tap.TypedArgs):
    dst: Path = tap.arg(positional=True, help="Destination file")
    files: list[Path] = tap.arg(positional=True, help="Source file", nargs="+")

def runner(args: Args):
    print(f"Print copying from '{args.src}' to '{args.dst}'")

def main() -> None:
    tap.Parser(Args).bind(runner).run()

if __name__ == "__main__":
    main()

usage: test.py [-h] dst files [files ...]

positional arguments:
  dst         Destination file
  files       Source file

options:
  -h, --help  show this help message and exit
bluenote10 commented 1 year ago

Thanks for the suggestion! Indeed, some features are already implemented, but I haven't had time to document them well. I've now added a section for multiple positional arguments in the docs.