I'd like to create an app that either loads a config file or inits a config file. The syntax i would like to achieve:
app /some/path/config.json # loads config.json
or
app init # create a config.json with some predefined stuff
The two different positional arguments would have related optional parameters.
I know I can use subparsers to achieve this:
argument = argparse.ArgumentParser()
subparser = argument.add_subparsers()
config_subparser = subparser.add_parser("config")
config_subparser.add_argument(
'config',
help='Path to configuration file.',
nargs='?'
)
init_subparser = subparser.add_parser("init")
init_subparser.add_argument(
'init',
help='initializes workspace'
)
But my problem is that this code has to be called with an additional 'config' string:
app config config.json
Is it possible to create a "nameless" positional param so that the 'config' string can be left out from the call?
Thanks in advance! :)