Call the function from the CLI. Parse command line arguments to get all arguments. :return: the return of main
(self, cli_args=None)
| 210 | self._arguments[argument.key] = argument |
| 211 | |
| 212 | def cli_noexit(self, cli_args=None): |
| 213 | ''' |
| 214 | Call the function from the CLI. Parse command line arguments |
| 215 | to get all arguments. |
| 216 | |
| 217 | :return: the return of main |
| 218 | ''' |
| 219 | parser = argparse.ArgumentParser( |
| 220 | description=self._description, |
| 221 | formatter_class=argparse.RawTextHelpFormatter, |
| 222 | ) |
| 223 | for key in self._arguments: |
| 224 | argument = self._arguments[key] |
| 225 | parser.add_argument(*argument.args, **argument.kwargs) |
| 226 | if argument.is_bool: |
| 227 | new_longname = '--no' + argument.longname[1:] |
| 228 | kwargs = argument.kwargs.copy() |
| 229 | kwargs['default'] = not argument.default |
| 230 | if kwargs['action'] in ('store_true', 'store_false'): |
| 231 | kwargs['action'] = 'store_false' |
| 232 | if 'help' in kwargs: |
| 233 | del kwargs['help'] |
| 234 | parser.add_argument(new_longname, dest=argument.key, **kwargs) |
| 235 | args = parser.parse_args(args=cli_args) |
| 236 | return self._do_main(vars(args)) |
| 237 | |
| 238 | def cli(self, *args, **kwargs): |
| 239 | ''' |
no test coverage detected