neuralib.argp.dispatch
A decorator that mark a function a dispatch target function. |
|
list all dispatch-decoratored function info in host. |
|
find dispatch-decoratored function in host according to command. |
|
invoke a dispatch-decoratored function in default group. |
|
invoke a dispatch-decoratored function in certain group. |
|
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')