if __name__ == '__main__':
    parser = ArgumentParser(prog='script.py')
parser.add_argument('--foo', nargs='?', metavar='bar', default='baz')
parser.print_usage()
for args in ([], ['--foo'], ['--foo', 'bar']):
    pass
Command line options with optional arguments in Python