def init_options_and_registry(args, command_modules): """Register command modules and determine options from commandline. These are coupled together for implementation simplicity. Conceptually they are unrelated but they share implementation details that can be encapsulated by combining them this way. Args: args: [list of command-line arguments] command_modules: See make_registry. Returns: options, registry Where: options: [Namespace] From parsed args. registry: [dict] of (<command-name>: <CommandFactory>) """ args, defaults = preprocess_args(args) parser = argparse.ArgumentParser(prog='buildtool.sh') init_standard_parser(parser, defaults) MetricsManager.init_argument_parser(parser, defaults) registry = make_registry(command_modules, parser, defaults) return parser.parse_args(args), registry
def init_options_and_registry(args, command_modules): """Register command modules and determine options from commandline. These are coupled together for implementation simplicity. Conceptually they are unrelated but they share implementation details that can be encapsulated by combining them this way. Args: args: [list of command-line arguments] command_modules: See make_registry. Returns: options, registry Where: options: [Namespace] From parsed args. registry: [dict] of (<command-name>: <CommandFactory>) """ args, defaults = preprocess_args(args) parser = argparse.ArgumentParser(prog='buildtool.sh') add_standard_parser_args(parser, defaults) MetricsManager.init_argument_parser(parser, defaults) registry = make_registry(command_modules, parser, defaults) options = parser.parse_args(args) options.program = 'buildtool' # Determine the version for monitoring purposes. # Depending on the options defined, this is either the branch or bom prefix. add_monitoring_context_labels(options) return options, registry
def get_options(args): """Resolve all the command-line options.""" args, defaults = preprocess_args( args, default_home_path_filename='validate_bom.yml') parser = argparse.ArgumentParser(prog='validate_bom.sh') add_standard_parser_args(parser, defaults) # DEPRECATED - use output_dir instead add_parser_argument(parser, 'log_dir', defaults, './validate_bom_results', help='Path to root directory for report output.') MetricsManager.init_argument_parser(parser, defaults) validate_bom__config.init_argument_parser(parser, defaults) validate_bom__deploy.init_argument_parser(parser, defaults) validate_bom__test.init_argument_parser(parser, defaults) options = parser.parse_args(args) options.program = 'validate_bom' options.command = 'validate_bom' # metrics assumes a "command" value. options.log_dir = options.output_dir # deprecated validate_bom__config.validate_options(options) validate_bom__test.validate_options(options) if not os.path.exists(options.log_dir): os.makedirs(options.log_dir) if options.influxdb_database == 'SpinnakerBuildTool': options.influxdb_database = 'SpinnakerValidate' # Add platform/spinnaker_type to each metric we produce. # We'll use this to distinguish what was being tested. context_labels = 'platform=%s,deployment_type=%s' % ( validate_bom__deploy.determine_deployment_platform(options), options.deploy_spinnaker_type) latest_unvalidated_suffix = '-latest-unvalidated' if options.deploy_version.endswith(latest_unvalidated_suffix): bom_series = options.deploy_version[:-len(latest_unvalidated_suffix)] else: bom_series = options.deploy_version[:options.deploy_version.rfind('-')] context_labels += ',version=%s' % bom_series if options.monitoring_context_labels: context_labels += ',' + options.monitoring_context_labels options.monitoring_context_labels = context_labels return options