Can argparse forward arguments to other python files?

Viewed 202

I'm writing a CLI with hundreds of arguments and sub modules in Python with argparse. For obvious reasons, I do not want these arguments all stacked in the same python file. Instead, I would prefer to delegate to other submodules and let users add their own submodule at will that will be automatically detected by the top level argparser.

As an example, we might have a directory that looks like the following:

- main.py
- foo.py
- bar.py
- baz/foo.py
...

One valid invocation of this CLI would be:

./main.py foo --help

This would bring up the help pane for the argparse module in foo.py

Another example would be:

./main.py baz foo --help

which would bring up the help pane for the argparse module in baz/foo.py.

And finally:

./main.py --help

Would print something like:

Options are:
  foo
  bar
  baz

If you haven't already guessed, this pattern is seen in kubectl, which seems to organize a plethora of options quite well.

Does a library like this exist or do I need to roll my own?

0 Answers
Related