def main(args=None): setup_default() args = args or sys.argv[:] # import logging_tree # logging_tree.printout() log.debug('args: %s', args) cli = galaxy.GalaxyCLI(args) try: cli.parse() except cli_exceptions.CliOptionsError as e: cli.parser.print_help() log.error(e) return os.EX_USAGE try: exit_code = cli.run() except exceptions.GalaxyError as e: log.exception(e) print(e) # exit with EX_SOFTWARE on generic error exit_code = os.EX_SOFTWARE # do any return code setup we need here return exit_code
def test_setup_default(mocker): mocker.patch('ansible_galaxy_cli.logger.setup.load_config_yaml', return_value=None) setup.setup_default() cli_logger = logging.getLogger('ansible_galaxy_cli') assert cli_logger.getEffectiveLevel() == logging.INFO # should have null handlers at least # no hasHandlers for py2.7 so just if hasattr(cli_logger, 'hasHandlers'): assert cli_logger.hasHandlers()
def main(args=None): setup_default() setup_custom() args = args or sys.argv[:] # import logging_tree # logging_tree.printout() log.debug('args: %s', args) cli = galaxy.GalaxyCLI(args) try: cli.parse() except cli_exceptions.CliOptionsError as e: cli.parser.print_help() log.error(e) return os.EX_USAGE # TODO: some level of exception mapper to set exit code based on exception try: exit_code = cli.run() except exceptions.GalaxyConfigFileError as e: log.exception(e) # The str(e)/error here maybe a multiline yaml error that looks # best on a fresh line stderr_log.error('Error loading configuration file %s:', e.config_file_path) stderr_log.error(e) return os.EX_CONFIG except exceptions.GalaxyError as e: log.exception(e) stderr_log.error(e) # exit with EX_SOFTWARE on generic error exit_code = os.EX_SOFTWARE except Exception as e: log.exception(e) stderr_log.error(e) exit_code = os.EX_SOFTWARE # let non-Galaxy exceptions bubble up and traceback log.debug('Uncaught exception for invocation: %s', cli._orig_args_copy) log.error('Uncaught exception, existing with exit code: %s', exit_code) raise log.debug('exit code: %s', exit_code) # do any return code setup we need here return exit_code