def main(): config = Config() parser = argparse.ArgumentParser( description=__doc__, usage='''epicli <command> [<args>]''', formatter_class=argparse.RawDescriptionHelpFormatter) # setup some root arguments parser.add_argument('--version', action='version', help='Shows the CLI version', version=VERSION) parser.add_argument( '--licenses', action='version', help= 'Shows the third party packages and their licenses the CLI is using.', version=json.dumps(LICENSES, indent=4)) parser.add_argument( '-l', '--log-file', dest='log_name', type=str, help='The name of the log file written to the output directory') parser.add_argument('--log-format', dest='log_format', type=str, help='Format for the logging string.') parser.add_argument('--log-date-format', dest='log_date_format', type=str, help='Format for the logging date.') parser.add_argument( '--log-count', dest='log_count', type=str, help='Roleover count where each CLI run will generate a new log.') parser.add_argument('--log-type', choices=['plain', 'json'], default='plain', dest='log_type', action='store', help='Type of logs.') parser.add_argument( '--validate-certs', choices=['true', 'false'], default='true', action='store', dest='validate_certs', help= '''[Experimental]: Disables certificate checks for certain Ansible operations which might have issues behind proxies (https://github.com/ansible/ansible/issues/32750). Should NOT be used in production for security reasons.''' ) parser.add_argument( '--debug', dest='debug', action="store_true", help= 'Set this to output extensive debug information. Carries over to Ansible and Terraform.' ) parser.add_argument( '--auto-approve', dest='auto_approve', action="store_true", help='Auto approve any user input queries asked by Epicli') # some arguments we don't want available when running from the docker image. if not config.docker_cli: parser.add_argument( '-o', '--output', dest='output_dir', type=str, help='Directory where the CLI should write it`s output.') # setup subparsers subparsers = parser.add_subparsers() apply_parser(subparsers) validate_parser(subparsers) init_parser(subparsers) upgrade_parser(subparsers) backup_parser(subparsers) recovery_parser(subparsers) delete_parser(subparsers) prepare_parser(subparsers) # check if there were any variables and display full help if len(sys.argv) < 2: parser.print_help() sys.exit(1) arguments = sys.argv[1:] # add some arguments to the general config so we can easily use them throughout the CLI args = parser.parse_args(arguments) config.output_dir = args.output_dir if hasattr(args, 'output_dir') else None config.log_file = args.log_name config.log_format = args.log_format config.log_date_format = args.log_date_format config.log_type = args.log_type config.log_count = args.log_count config.validate_certs = True if args.validate_certs == 'true' else False if 'offline_requirements' in args and not args.offline_requirements is None: config.offline_requirements = args.offline_requirements if 'wait_for_pods' in args and not args.wait_for_pods is None: config.wait_for_pods = args.wait_for_pods config.debug = args.debug config.auto_approve = args.auto_approve try: return args.func(args) except Exception as e: logger = Log('epicli') logger.error(e, exc_info=config.debug) return 1
def main(): config = Config() parser = argparse.ArgumentParser( description=__doc__, usage='''epicli <command> [<args>]''', formatter_class=argparse.RawTextHelpFormatter) # setup some root arguments parser.add_argument('--version', action='version', help='Shows the CLI version', version=VERSION) parser.add_argument( '--licenses', action='version', help= 'Shows the third party packages and their licenses the CLI is using.', version=json.dumps(LICENSES, indent=4)) parser.add_argument( '-l', '--log-file', dest='log_name', type=str, help='The name of the log file written to the output directory') parser.add_argument('--log-format', dest='log_format', type=str, help='Format for the logging string.') parser.add_argument('--log-date-format', dest='log_date_format', type=str, help='Format for the logging date.') parser.add_argument( '--log-count', dest='log_count', type=str, help='Roleover count where each CLI run will generate a new log.') parser.add_argument('--log-type', choices=['plain', 'json'], default='plain', dest='log_type', action='store', help='Type of logs.') parser.add_argument( '--validate-certs', choices=['true', 'false'], default='true', action='store', dest='validate_certs', help= '''[Experimental]: Disables certificate checks for certain Ansible operations which might have issues behind proxies (https://github.com/ansible/ansible/issues/32750). Should NOT be used in production for security reasons.''') parser.add_argument( '--auto-approve', dest='auto_approve', action="store_true", help='Auto approve any user input queries asked by Epicli') # set debug verbosity level. def debug_level(x): x = int(x) if x < 0 or x > 4: raise argparse.ArgumentTypeError( "--debug value should be between 0 and 4") return x parser.add_argument( '--debug', dest='debug', type=debug_level, help='''Set this flag (0..4) to enable debug output where 0 is no debug output and 1..4 is debug output with different verbosity levels: Python : Anything heigher then 0 enables printing of Python stacktraces Ansible : 1..4 map to following Ansible verbosity levels: 1: -v 2: -vv 3: -vvv 4: -vvvv Terraform : 1..4 map to the following Terraform verbosity levels: 1: WARN 2: INFO 3: DEBUG 4: TRACE''') # some arguments we don't want available when running from the docker image. if not config.docker_cli: parser.add_argument( '-o', '--output', dest='output_dir', type=str, help='Directory where the CLI should write it`s output.') # setup subparsers subparsers = parser.add_subparsers() prepare_parser(subparsers) init_parser(subparsers) apply_parser(subparsers) upgrade_parser(subparsers) delete_parser(subparsers) test_parser(subparsers) ''' validate_parser(subparsers) ''' backup_parser(subparsers) recovery_parser(subparsers) # check if there were any variables and display full help if len(sys.argv) < 2: parser.print_help() sys.exit(1) arguments = sys.argv[1:] # add some arguments to the general config so we can easily use them throughout the CLI args = parser.parse_args(arguments) config.output_dir = getattr(args, 'output_dir', None) config.log_file = args.log_name config.log_format = args.log_format config.log_date_format = args.log_date_format config.log_type = args.log_type config.log_count = args.log_count config.validate_certs = True if args.validate_certs == 'true' else False if 'offline_requirements' in args and not args.offline_requirements is None: config.offline_requirements = args.offline_requirements if 'wait_for_pods' in args and not args.wait_for_pods is None: config.wait_for_pods = args.wait_for_pods config.debug = args.debug config.auto_approve = args.auto_approve try: return args.func(args) except Exception as e: logger = Log('epicli') logger.error(e, exc_info=(config.debug > 0)) dump_debug_info() return 1