def __init__(self, message=None, ctx=None, param=None, param_hint=None, param_type=None): MissingParameter.__init__(self, message, ctx, param, param_hint) self.param_type = param_type
def deploy(context, application_id, module, all_modules, strategy, safe_deploy_strategy, live_logs, output, no_color): # TODO find a "clicker" way to do this parameter validation if not module and not all_modules: raise MissingParameter( 'You must have one (and only one) from --module and --all-modules parameters', param_hint='module', param_type='parameter') if module and all_modules: raise BadParameter( 'You must have only one from --module and --all-modules parameters', param_hint='module') if all_modules: app = context.apps.retrieve(application_id) module = [m["name"] for m in app["modules"]] modules = [] for m in module: name, rev = m.split(':') if ':' in m else (m, None) mod = {"name": name} if rev: mod["rev"] = rev modules.append(mod) try: job_id = context.jobs.command_deploy(application_id, modules, strategy, safe_deploy_strategy) handle_job_creation(context, job_id, live_logs, output, no_color) except ApiClientException as e: raise ClickException(e) from e
def handle_parse_result(self, ctx, opts, args): cleaned_opts = set([o.replace('_', '-') for o in opts.keys()]) if len(cleaned_opts.intersection(set(self.one_of))) == 0: raise MissingParameter('One of {} must be provided.'.format(self.one_of)) if len(cleaned_opts.intersection(set(self.one_of))) > 1: raise UsageError('Only one of {} should be provided.'.format(self.one_of)) return super(OneOfOption, self).handle_parse_result(ctx, opts, args)
def fallback_to_stdin(ctx, args, value): stdin = click.get_text_stream("stdin") if not value and not isatty(stdin): stdin_arg = stdin.readline().strip() else: stdin_arg = value if not stdin_arg: raise MissingParameter("No value specified!") return stdin_arg
def full_process_value(self, ctx, value): value = super(OptionRequiredIf, self).full_process_value(ctx, value) ex_str = ', '.join(self.required_option) ex_str = ex_str.replace("-", "_") if value is None and ctx.params[ex_str] is not None: msg = 'The argument `{}` is required if `{}` is used.'.format( self.name, ', '.join(self.required_option) ) raise MissingParameter(ctx=ctx, param=self, message=msg) return value
def fallback_to_stdin(ctx, args, value): if value: return value stdin = click.get_text_stream("stdin") if not isatty(stdin): value = stdin.readline().strip() if not value: raise MissingParameter("No value specified!") return value
def check_params(params, params_descriptor, group): """Check a list of parameters.""" if group not in params: raise BadParameter(f"'{group}' group not in parameters.") for param_name, param_values in params_descriptor.items(): if param_name not in params[group] or params[group][param_name] == "": if "kwargs" in param_values and "default" in param_values["kwargs"]: params[group][param_name] = param_values["kwargs"]["default"] else: raise MissingParameter(param_type=param_name.replace("_", " ")) if param_name == "name": param = params[group][param_name] params[group][param_name] = param.replace(" ", "_")
def handle_parse_result(self, ctx, opts, args): using_required_option = self.name in opts using_dependent_options = all( opt.replace('-', '_') in opts for opt in self.required_option) option_name = self.name.replace('_', '-') if not using_required_option and using_dependent_options: msg = output_messages['ERROR_REQUIRED_OPTION_MISSING'].format( option_name, ', '.join(self.required_option), option_name) if not is_wizard_enabled(): raise MissingParameter(ctx=ctx, param=self, message=msg) requested_value = wizard_for_field(ctx, None, msg, required=True) opts[self.name] = requested_value return super(OptionRequiredIf, self).handle_parse_result(ctx, opts, args) elif using_required_option and not using_dependent_options: log.warn(output_messages['WARN_USELESS_OPTION'].format( option_name, ', '.join(self.required_option))) return super(OptionRequiredIf, self).handle_parse_result(ctx, opts, args)
def full_process_value(self, ctx, value): """ Slightly modified copy of ``Option.full_process_value()`` that records which options use default values in ``ctx.meta['raiden.options_using_default']``. This is then used in ``apply_config_file()`` to establish precedence between values given via the config file and the cli. """ if value is None and self.prompt is not None and not ctx.resilient_parsing: # type: ignore return self.prompt_for_value(ctx) value = self.process_value(ctx, value) if value is None: value = self.get_default(ctx) if not self.value_is_missing(value): ctx.meta.setdefault(CONTEXT_KEY_DEFAULT_OPTIONS, set()).add(self.name) if self.required and self.value_is_missing(value): raise MissingParameter(ctx=ctx, param=self) return value
def load_and_check_params( group, params_descriptor, params_as_list, interactive, config, riotbase, in_riot_dir=None, ): """Load, prompt and check configuration parameters.""" if not interactive and config is None: raise MissingParameter( param_type="--interactive and/or --config options") check_riotbase(riotbase) riotbase = os.path.abspath(os.path.expanduser(riotbase)) params = {group: {}, "global": {}} if config is not None: params = read_config_file(config, group) if in_riot_dir is None: params[group]["riotbase"] = riotbase elif "global" in params: params["global"]["license"] = "LGPL21" if interactive: prompt_params(params, params_descriptor, group) prompt_params_list(params, group, *params_as_list) prompt_global_params(params) load_license(params, " * ") check_params(params, params_descriptor, group) if "global" in params: check_global_params(params) return params
def _check_param(params, param): if param not in params or params[param] == "": raise MissingParameter(param_type=param.replace("_", " "))
def check_riotbase(riotbase): """Check the given path is a valid RIOTBASE directory.""" if riotbase is None or not riotbase: raise MissingParameter(param_type="riotbase directory")