Lines Matching refs:action

129         action='ignore',
288 def add_argument(self, action): argument
289 if action.help is not SUPPRESS:
293 invocations = [get_invocation(action)]
294 for subaction in self._iter_indented_subactions(action):
304 self._add_item(self._format_action, [action])
307 for action in actions:
308 self.add_argument(action)
344 for action in actions:
345 if action.option_strings:
346 optionals.append(action)
348 positionals.append(action)
429 for action in group._group_actions:
430 group_actions.add(action)
442 for i, action in enumerate(actions):
446 if action.help is SUPPRESS:
454 elif not action.option_strings:
455 part = self._format_args(action, action.dest)
458 if action in group_actions:
467 option_string = action.option_strings[0]
471 if action.nargs == 0:
477 default = action.dest.upper()
478 args_string = self._format_args(action, default)
482 if not action.required and action not in group_actions:
514 def _format_action(self, action): argument
520 action_header = self._format_action_invocation(action)
523 if not action.help:
543 if action.help:
544 help_text = self._expand_help(action)
555 for subaction in self._iter_indented_subactions(action):
561 def _format_action_invocation(self, action): argument
562 if not action.option_strings:
563 metavar, = self._metavar_formatter(action, action.dest)(1)
571 if action.nargs == 0:
572 parts.extend(action.option_strings)
577 default = action.dest.upper()
578 args_string = self._format_args(action, default)
579 for option_string in action.option_strings:
584 def _metavar_formatter(self, action, default_metavar): argument
585 if action.metavar is not None:
586 result = action.metavar
587 elif action.choices is not None:
588 choice_strs = [str(choice) for choice in action.choices]
600 def _format_args(self, action, default_metavar): argument
601 get_metavar = self._metavar_formatter(action, default_metavar)
602 if action.nargs is None:
604 elif action.nargs == OPTIONAL:
606 elif action.nargs == ZERO_OR_MORE:
608 elif action.nargs == ONE_OR_MORE:
610 elif action.nargs == REMAINDER:
612 elif action.nargs == PARSER:
615 formats = ['%s' for _ in range(action.nargs)]
616 result = ' '.join(formats) % get_metavar(action.nargs)
619 def _expand_help(self, action): argument
620 params = dict(vars(action), prog=self._prog)
630 return self._get_help_string(action) % params
632 def _iter_indented_subactions(self, action): argument
634 get_subactions = action._get_subactions
652 def _get_help_string(self, action): argument
653 return action.help
685 def _get_help_string(self, action): argument
686 help = action.help
687 if '%(default)' not in action.help:
688 if action.default is not SUPPRESS:
690 if action.option_strings or action.nargs in defaulting_nargs:
1257 for action in self._actions:
1258 if action.dest in kwargs:
1259 action.default = kwargs[action.dest]
1262 for action in self._actions:
1263 if action.dest == dest and action.default is not None:
1264 return action.default
1302 action = action_class(**kwargs)
1305 type_func = self._registry_get('type', action.type, action.type)
1309 return self._add_action(action)
1321 def _add_action(self, action): argument
1323 self._check_conflict(action)
1326 self._actions.append(action)
1327 action.container = self
1330 for option_string in action.option_strings:
1331 self._option_string_actions[option_string] = action
1334 for option_string in action.option_strings:
1340 return action
1342 def _remove_action(self, action): argument
1343 self._actions.remove(action)
1367 for action in group._group_actions:
1368 group_map[action] = title_group_map[group.title]
1378 for action in group._group_actions:
1379 group_map[action] = mutex_group
1382 for action in container._actions:
1383 group_map.get(action, self)._add_action(action)
1437 action = kwargs.pop('action', default)
1438 return self._registry_get('action', action, action)
1449 def _check_conflict(self, action): argument
1453 for option_string in action.option_strings:
1461 conflict_handler(action, confl_optionals)
1463 def _handle_conflict_error(self, action, conflicting_actions): argument
1466 for option_string, action
1468 raise ArgumentError(action, message % conflict_string)
1470 def _handle_conflict_resolve(self, action, conflicting_actions): argument
1473 for option_string, action in conflicting_actions:
1476 action.option_strings.remove(option_string)
1481 if not action.option_strings:
1482 action.container._remove_action(action)
1508 def _add_action(self, action): argument
1509 action = super(_ArgumentGroup, self)._add_action(action)
1510 self._group_actions.append(action)
1511 return action
1513 def _remove_action(self, action): argument
1514 super(_ArgumentGroup, self)._remove_action(action)
1515 self._group_actions.remove(action)
1525 def _add_action(self, action): argument
1526 if action.required:
1529 action = self._container._add_action(action)
1530 self._group_actions.append(action)
1531 return action
1533 def _remove_action(self, action): argument
1534 self._container._remove_action(action)
1535 self._group_actions.remove(action)
1610 '-h', '--help', action='help', default=SUPPRESS,
1614 '-v', '--version', action='version', default=SUPPRESS,
1671 action = parsers_class(option_strings=[], **kwargs)
1672 self._subparsers._add_action(action)
1675 return action
1677 def _add_action(self, action): argument
1678 if action.option_strings:
1679 self._optionals._add_action(action)
1681 self._positionals._add_action(action)
1682 return action
1685 return [action
1686 for action in self._actions
1687 if action.option_strings]
1690 return [action
1691 for action in self._actions
1692 if not action.option_strings]
1714 for action in self._actions:
1715 if action.dest is not SUPPRESS:
1716 if not hasattr(namespace, action.dest):
1717 if action.default is not SUPPRESS:
1718 default = action.default
1719 if isinstance(action.default, _basestring):
1720 default = self._get_value(action, default)
1721 setattr(namespace, action.dest, default)
1782 def take_action(action, argument_strings, option_string=None): argument
1783 seen_actions.add(action)
1784 argument_values = self._get_values(action, argument_strings)
1789 if argument_values is not action.default:
1790 seen_non_default_actions.add(action)
1791 for conflict_action in action_conflicts.get(action, []):
1795 raise ArgumentError(action, msg % action_name)
1800 action(self, namespace, argument_values, option_string)
1807 action, option_string, explicit_arg = option_tuple
1816 if action is None:
1823 arg_count = match_argument(action, 'A')
1830 action_tuples.append((action, [], option_string))
1836 action = optionals_map[option_string]
1840 raise ArgumentError(action, msg % explicit_arg)
1847 action_tuples.append((action, args, option_string))
1854 raise ArgumentError(action, msg % explicit_arg)
1862 arg_count = match_argument(action, selected_patterns)
1865 action_tuples.append((action, args, option_string))
1871 for action, args, option_string in action_tuples:
1872 take_action(action, args, option_string)
1888 for action, arg_count in zip(positionals, arg_counts):
1891 take_action(action, args)
1946 for action in self._actions:
1947 if action.required:
1948 if action not in seen_actions:
1949 name = _get_action_name(action)
1955 for action in group._group_actions:
1956 if action in seen_non_default_actions:
1961 names = [_get_action_name(action)
1962 for action in group._group_actions
1963 if action.help is not SUPPRESS]
2002 def _match_argument(self, action, arg_strings_pattern): argument
2004 nargs_pattern = self._get_nargs_pattern(action)
2014 default = _('expected %s argument(s)') % action.nargs
2015 msg = nargs_errors.get(action.nargs, default)
2016 raise ArgumentError(action, msg)
2027 pattern = ''.join([self._get_nargs_pattern(action)
2028 for action in actions_slice])
2048 action = self._option_string_actions[arg_string]
2049 return action, arg_string, None
2059 action = self._option_string_actions[option_string]
2060 return action, option_string, explicit_arg
2069 for action, option_string, explicit_arg in option_tuples])
2108 action = self._option_string_actions[option_string]
2109 tup = action, option_string, explicit_arg
2123 action = self._option_string_actions[option_string]
2124 tup = action, option_string, short_explicit_arg
2127 action = self._option_string_actions[option_string]
2128 tup = action, option_string, explicit_arg
2138 def _get_nargs_pattern(self, action): argument
2141 nargs = action.nargs
2172 if action.option_strings:
2182 def _get_values(self, action, arg_strings): argument
2184 if action.nargs not in [PARSER, REMAINDER]:
2188 if not arg_strings and action.nargs == OPTIONAL:
2189 if action.option_strings:
2190 value = action.const
2192 value = action.default
2194 value = self._get_value(action, value)
2195 self._check_value(action, value)
2199 elif (not arg_strings and action.nargs == ZERO_OR_MORE and
2200 not action.option_strings):
2201 if action.default is not None:
2202 value = action.default
2205 self._check_value(action, value)
2208 elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]:
2210 value = self._get_value(action, arg_string)
2211 self._check_value(action, value)
2214 elif action.nargs == REMAINDER:
2215 value = [self._get_value(action, v) for v in arg_strings]
2218 elif action.nargs == PARSER:
2219 value = [self._get_value(action, v) for v in arg_strings]
2220 self._check_value(action, value[0])
2224 value = [self._get_value(action, v) for v in arg_strings]
2226 self._check_value(action, v)
2231 def _get_value(self, action, arg_string): argument
2232 type_func = self._registry_get('type', action.type, action.type)
2235 raise ArgumentError(action, msg % type_func)
2243 name = getattr(action.type, '__name__', repr(action.type))
2245 raise ArgumentError(action, msg)
2249 name = getattr(action.type, '__name__', repr(action.type))
2251 raise ArgumentError(action, msg % (name, arg_string))
2256 def _check_value(self, action, value): argument
2258 if action.choices is not None and value not in action.choices:
2259 tup = value, ', '.join(map(repr, action.choices))
2261 raise ArgumentError(action, msg)