ArgparseControlleras examples (again, imported as
basecontroller responsible for handling runtime dispatch. All other controllers are then stacked on top of the base controller (or other controllers already stacked on base). The base controller is the root of the application's command-line namespace.
clitab that running
python myapp.pywithout any arguments produces help output (same as if passing
--help). This is the default action of the
ArgparseController, but can be modified by overriding the
Controller.Meta.argumentsand are displayed/used at the top level of that controller, while sub-command level arguments are defined via the
ex()decorator and only displayed and used under that sub-command namespace.
Base.cmd1()method/sub-command. This worked fine. However, because controller level arguments should be considered global to the entire namespace, we should reduce duplicate code and handle controller level argument parsing in one place, regardless of what sub-command is passed.
ArgparseControllerdefines both a
_post_argument_parsingmethod for providing direct access to that controller's sub-parser (
self._parser) and processing arguments. This is very similar to the
post_argument_parsingframework hooks, but local in scope to the controller.
stackedonto the base controller (or any other controller) in one of two ways:
embedded- The controllers commands and arguments are included under the parent controller's name space.
nested- The controller label is added as a sub-command under the parent controller's namespace (effectively this is a sub-command with additional sub-sub-commands under it)
basecontroller is accessed when calling
myapp.pydirectly. Any commands under the
basecontroller would be accessible as
myapp.py <cmd1>, or
myapp.py <cmd2>, etc. An
embeddedcontroller will merge its commands and options into the
basecontroller namespace and appear to be part of the base controller... meaning you would still access the
embeddedcontrollers commands as
myapp.py <embedded_cmd1>, etc (same for options).
nestedcontrollers, a prefix will be created with that controller's label under its parent's namespace. Therefore you would access that controller's commands and options as
myapp.py <controller_label> <controller_cmd1>.