def _format_error(error: Exception, ) -> str: error_stream = StringIO() print_error( stream=error_stream, error=error, ) return error_stream.getvalue()
def _serialize_error( self, error: Optional[Exception], ) -> Optional[str]: if not error: return None error_stream = StringIO() print_error( error=error, stream=error_stream, ) return error_stream.getvalue()
def validate_configuration( self, configuration: RootConfiguration, ) -> None: try: configuration.validate() except AttributesError as e: error_stream = StringIO() print_error( error=e, stream=error_stream, ) self.fail(error_stream.getvalue())
def run(*args: str, ) -> None: """ Run the CLI. Args: args: command line arguments """ if not args: args = tuple(sys.argv[1:]) parsed = _parse_args(*args) try: parsed.func(parsed) except CoreException as e: print_error(error=e, ) sys.exit(1) except KeyboardInterrupt: print_error_message(message='Interrupted by user.', ) sys.exit(130) sys.exit(0)