The CLIRouter provides a chainable router that can be used to route a CLI command to a Python function
| 118 | |
| 119 | |
| 120 | class CLIRouter(Router): |
| 121 | """The CLIRouter provides a chainable router that can be used to route a CLI command to a Python function""" |
| 122 | |
| 123 | __slots__ = () |
| 124 | |
| 125 | def __init__(self, name=None, version=None, doc=None, **kwargs): |
| 126 | super().__init__(**kwargs) |
| 127 | if name is not None: |
| 128 | self.route["name"] = name |
| 129 | if version: |
| 130 | self.route["version"] = version |
| 131 | if doc: |
| 132 | self.route["doc"] = doc |
| 133 | |
| 134 | def name(self, name, **overrides): |
| 135 | """Sets the name for the CLI interface""" |
| 136 | return self.where(name=name, **overrides) |
| 137 | |
| 138 | def version(self, version, **overrides): |
| 139 | """Sets the version for the CLI interface""" |
| 140 | return self.where(version=version, **overrides) |
| 141 | |
| 142 | def doc(self, documentation, **overrides): |
| 143 | """Sets the documentation for the CLI interface""" |
| 144 | return self.where(doc=documentation, **overrides) |
| 145 | |
| 146 | def __call__(self, api_function): |
| 147 | """Enables exposing a Hug compatible function as a Command Line Interface""" |
| 148 | hug.interface.CLI(self.route, api_function) |
| 149 | return api_function |
| 150 | |
| 151 | |
| 152 | class InternalValidation(Router): |
no outgoing calls