Argparse optional positional arguments?

I have a script which is meant to be used like this:

usage: installer.py dir [-h] [-v]

dir is a positional argument which is defined like this:

parser.add_argument('dir', default=os.getcwd())

I want the dir to be optional: when it's not specified it should just be cwd.

Unfortunately, when I don't specify the dir argument, I get Error: Too few arguments.

← Назад к списку