Ejemplo n.º 1
0
    def ShortFlag(self,
                  short_name,
                  arg_type=None,
                  default=None,
                  quit_parsing_flags=False,
                  help=None):
        # type: (str, int, Optional[Any], bool, Optional[str]) -> None
        """ -c """
        assert short_name.startswith('-'), short_name
        assert len(short_name) == 2, short_name

        char = short_name[1]
        if arg_type is None:
            assert quit_parsing_flags == False
            typ = flag_type.Bool()  # type: flag_type_t
            self.actions_short[char] = args.SetToTrue(char)
        else:
            typ = _FlagType(arg_type)
            self.actions_short[char] = args.SetToArgAction(
                char, typ, quit_parsing_flags=quit_parsing_flags)

        if self.typed:
            self.defaults[char] = _Default(arg_type, arg_default=default)
        else:
            self.defaults[char] = args.PyToValue(default)
        self.fields[char] = typ
Ejemplo n.º 2
0
    def LongFlag(
            self,
            long_name,  # type: str
            arg_type=None,  # type: Union[List[str], None, int]
            default=None,  # type: Optional[Any]
            help=None,  # type: Optional[str]
    ):
        # type: (...) -> None
        """ --rcfile """
        assert long_name.startswith('--'), long_name

        # TODO: Move this to runtime?  So you don't have duplicate flag and key
        name = long_name[2:]
        if arg_type is None:
            typ = flag_type.Bool()  # type: flag_type_t
            self.actions_long[long_name] = args.SetToTrue(name)
        else:
            typ = _FlagType(arg_type)
            self.actions_long[long_name] = args.SetToArgAction(name, typ)

        attr_name = name.replace('-', '_')
        if self.typed:
            self.defaults[attr_name] = _Default(arg_type, arg_default=default)
            #from core.pyerror import log
            #log('%s DEFAULT %s', attr_name, self.defaults[attr_name])
        else:
            self.defaults[attr_name] = args.PyToValue(default)
        self.fields[attr_name] = typ
Ejemplo n.º 3
0
    def Flag(self, name, arg_type, default=None, help=None):
        # type: (str, int, Optional[Any], Optional[str]) -> None
        """
    Args:
      name: e.g. '-no-docstring'
      arg_type: e.g. Str
    """
        assert name.startswith('-') and not name.startswith('--'), name

        attr_name = name[1:].replace('-', '_')
        if arg_type == args.Bool:
            self.arity1[attr_name] = args.SetBoolToArg(attr_name)
        else:
            self.arity1[attr_name] = args.SetToArgAction(
                attr_name, _FlagType(arg_type))

        self.defaults[attr_name] = args.PyToValue(default)
Ejemplo n.º 4
0
    def ShortFlag(self, short_name, arg_type=None, help=None):
        # type: (str, Optional[int], Optional[str]) -> None
        """
    This is very similar to ShortFlag for FlagSpecAndMore, except we have
    separate arity0 and arity1 dicts.
    """
        assert short_name.startswith('-'), short_name
        assert len(short_name) == 2, short_name

        char = short_name[1]
        if arg_type is None:
            self.arity0.append(char)
        else:
            self.arity1[char] = args.SetToArgAction(char, _FlagType(arg_type),
                                                    False)

        typ = _FlagType(arg_type)
        self.defaults[char] = _Default(arg_type)
        self.fields[char] = typ