def get_cmd(self, **kwargs): # base is a required property. cmd = kwargs['base'].split() # Iterate over _actions to preserve original order for action in self.parser._actions: name = ArgparseUtils.get_name(action) if name in kwargs: action_cli_text = self.get_action_cli_text(action, name, kwargs[name]) if action_cli_text: cmd.extend(action_cli_text) return cmd
def get_cmd(self, **kwargs): # base is a required property. cmd = kwargs['base'].split() # Iterate over _actions to preserve original order for action in self.parser._actions: name = ArgparseUtils.get_name(action) if name in kwargs: action_cli_text = self.get_action_cli_text( action, name, kwargs[name]) if action_cli_text: cmd.extend(action_cli_text) return cmd
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)