Adds a decorator main that will parse command line arguments based on the type annotations of that function.
This decorator supports:
Positional arguments via Python 3.8+'s support for positional-only arguments with the / syntax.
Nested dataclasses as arguments to a function.
Automatically parsing the help string based on the docstring of the function.
Example:
import pathlib
import simple_parsing as sp
@sp.decorators.main
def mkdir(path: pathlib.Path, /, *, parents: bool = False, exist_ok: bool = False) -> None:
""" Make a directory.
Args:
path: Path at which to create the directory.
parents: Whether to create parent directories.
exist_ok: If exist_ok is True `FileExistsError` will be raised.
"""
path.mkdir(parents=parents, exist_ok=exist_ok)
if __name__ == '__main__':
mkdir()
Adds a decorator
main
that will parse command line arguments based on the type annotations of that function.This decorator supports:
/
syntax.Example: