neuralib.argp.dispatch

dispatch

A decorator that mark a function a dispatch target function.

list_commands

list all dispatch-decoratored function info in host.

find_command

find dispatch-decoratored function in host according to command.

invoke_command

invoke a dispatch-decoratored function in default group.

invoke_group_command

invoke a dispatch-decoratored function in certain group.

DispatchOption

DispatchCommandNotFound

Value dispatch function

author:

Ta-Shun Su

Work with AbstractParser.

>>> from neuralib.argp import AbstractParser
>>> class Test(AbstractParser, DispatchOption):
...     target: str = DispatchOption.argument(
...         '--run'
...     )
...
...     @classmethod
...     def EPILOG(cls): # build parser epilog
...         return f'''... Command (--run)
... {textwrap.indent(Test.parser_command_epilog(), "  ")}
... '''
...
...     def run(self):
...         # dispaatch function call according to self.target
...         self.invoke_command(self.target)
...
...     @DispatchOption.dispatch('A')
...     def run_a(self):
...         '''doc A.'''
...         print('a')
...     @DispatchOption.dispatch('B')
...     def run_b(self):
...         '''doc B'''
...         print('b')