(self, *args, **kwargs)
return self._add_action(action)
add_argument(dest, ..., name=value, ...)
        add_argument(option_string, option_string, ..., name=value, ...)
add_argument(dest, ..., name=value, ...)
        add_argument(option_string, option_string, ..., name=value, ...)
add_argument ( dest ... name = value ... ) add_argument ( option_string option_string ... name = value ... )
def add_argument(self, *args, **kwargs):
        """
        add_argument(dest, ..., name=value, ...)
        add_argument(option_string, option_string, ..., name=value, ...)
        """

        # if no positional args are supplied or only one is supplied and
        # it doesn't look like an option string, parse a positional
        # argument
        chars = self.prefix_chars
        if not args or len(args) == 1 and args[0][0] not in chars:
            if args and 'dest' in kwargs:
                raise ValueError('dest supplied twice for positional argument')
            kwargs = self._get_positional_kwargs(*args, **kwargs)

        # otherwise, we're adding an optional argument
        else:
            kwargs = self._get_optional_kwargs(*args, **kwargs)

        # if no default was supplied, use the parser-level default
        if 'default' not in kwargs:
            dest = kwargs['dest']
            if dest in self._defaults:
                kwargs['default'] = self._defaults[dest]
            elif self.argument_default is not None:
                kwargs['default'] = self.argument_default

        # create the action object, and add it to the parser
        action_class = self._pop_action_class(kwargs)
        if not callable(action_class):
            raise ValueError('unknown action "%s"' % (action_class,))
        action = action_class(**kwargs)

        # raise an error if the action type is not callable
        type_func = self._registry_get('type', action.type, action.type)
        if not callable(type_func):
            raise ValueError('%r is not callable' % (type_func,))

        if type_func is FileType:
            raise ValueError('%r is a FileType class object, instance of it'
                             ' must be passed' % (type_func,))

        # raise an error if the metavar does not match the type
        if hasattr(self, "_get_formatter"):
            try:
                self._get_formatter()._format_args(action, None)
            except TypeError:
                raise ValueError("length of metavar tuple does not match nargs")

        return self._add_action(action)
def add_argument ( self , * args , * * kwargs ) : # if no positional args are supplied or only one is supplied and # it doesn't look like an option string, parse a positional # argument chars = self . prefix_chars if not args or len ( args ) == 1 and args [ 0 ] [ 0 ] not in chars : if args and 'dest' in kwargs : raise ValueError ( 'dest supplied twice for positional argument' ) kwargs = self . _get_positional_kwargs ( * args , * * kwargs ) # otherwise, we're adding an optional argument else : kwargs = self . _get_optional_kwargs ( * args , * * kwargs ) # if no default was supplied, use the parser-level default if 'default' not in kwargs : dest = kwargs [ 'dest' ] if dest in self . _defaults : kwargs [ 'default' ] = self . _defaults [ dest ] elif self . argument_default is not None : kwargs [ 'default' ] = self . argument_default # create the action object, and add it to the parser action_class = self . _pop_action_class ( kwargs ) if not callable ( action_class ) : raise ValueError ( 'unknown action "%s"' % ( action_class , ) ) action = action_class ( * * kwargs ) # raise an error if the action type is not callable type_func = self . _registry_get ( 'type' , action . type , action . type ) if not callable ( type_func ) : raise ValueError ( '%r is not callable' % ( type_func , ) ) if type_func is FileType : raise ValueError ( '%r is a FileType class object, instance of it' ' must be passed' % ( type_func , ) ) # raise an error if the metavar does not match the type if hasattr ( self , "_get_formatter" ) : try : self . _get_formatter ( ) . _format_args ( action , None ) except TypeError : raise ValueError ( "length of metavar tuple does not match nargs" ) return self . _add_action ( action )