My code is as follows.
__version__ = 'v10'
class MyHelpFormatter(argparse.ArgumentDefaultsHelpFormatter):
def _get_help_string(self, action):
return action.help
def main():
parser = argparse.ArgumentParser(
formatter_class=MyHelpFormatter,
description=__version__
)
parser.print_usage = parser.print_help
parser.add_argument("file", help="path to file/directory")
parser.add_argument(
"-t",
"--type",
type=str,
default=False,
help="file type",
)
parser.add_argument(
"-c",
"--config",
action="store_true",
help="change custom text",
)
parser.add_argument(
"-v",
"--version",
action='version',
version=__version__,
help="thumb-gen version",
)
In my code, it always requires the 'file' argument. It's ok.
Now I want call a function when it call with '--config' argument. But when I run main.py --config
it also require the 'file' argument.
How to use the '-config' argument without entering the required argument?