def get_action_cli_text(self, action, name, value): # positional args are always required and only expect value. if ArgparseUtils.is_positional(action): return [value] default = ArgparseUtils.get_default(action) # for format since it is doubly hacked we keep making exceptions. if name != 'format' and str(default) == str(value): return [] # expand the array into a repetition. if ArgparseUtils.is_repeated_action(action): cli_text = [] for v in value: cli_text.append(action.option_strings[0]) cli_text.append(v) return cli_text # Special handling for boolean if ArgparseUtils.get_type(action) == 'boolean': include_action = ArgparseUtils.is_boolean_included(action, value) # For booleans we only include the option_string. # e.g. --wait instead of --wait=True. return [action.option_strings[0]] if include_action else None # will end up being of the form "option_string value" return [ action.option_strings[0], six.moves.shlex_quote( # pylint: disable=too-many-function-args str(value)) ]
def _parse_parameter(self, action, parser): if self._test_skip_action(action, parser): return None, None name = ArgparseUtils.get_name(action) # All positionals outside of a mutually exclusive group are required. required = self._is_required(action, parser) # type is string if not specified otherwise type_ = ArgparseUtils.get_type(action) # for a few actions default is defined by type(action) default = ArgparseUtils.get_default(action, type_=type_) # Make sure choices are included in the description. Often action.help # may not list choices. It is perhaps better if this type were an enum? description = str(action.help) if not action.choices else \ '%s (choices: %s)' % (action.help, ', '.join(map(str, action.choices))) return name, self._get_parameter(default=default, description=description, type_=type_, required=required)
def _parse_parameter(self, action, parser): if self._test_skip_action(action, parser): return None, None name = ArgparseUtils.get_name(action) # All positionals outside of a mutually exclusive group are required. required = self._is_required(action, parser) # type is string if not specified otherwise type_ = ArgparseUtils.get_type(action) # for a few actions default is defined by type(action) default = ArgparseUtils.get_default(action, type_=type_) # Make sure choices are included in the description. Often action.help # may not list choices. It is perhaps better if this type were an enum? descripton = str(action.help) if not action.choices else \ '%s (choices: %s)' % (action.help, ', '.join(action.choices)) return name, self._get_parameter(default=default, description=descripton, type_=type_, required=required)
def get_action_cli_text(self, action, name, value): # positional args are always required and only expect value. if ArgparseUtils.is_positional(action): return [value] default = ArgparseUtils.get_default(action) # for format since it is doubly hacked we keep making exceptions. if name != 'format' and str(default) == str(value): return [] # expand the array into a repetition. if ArgparseUtils.is_repeated_action(action): cli_text = [] for v in value: cli_text.append(action.option_strings[0]) cli_text.append(v) return cli_text # Special handling for boolean if ArgparseUtils.get_type(action) == 'boolean': include_action = ArgparseUtils.is_boolean_included(action, value) # For booleans we only include the option_string. # e.g. --wait instead of --wait=True. return [action.option_strings[0]] if include_action else None # will end up being of the form "option_string value" return [action.option_strings[0], six.moves.shlex_quote(str(value))]