def add_option(self, *args, **kwargs):
        """add_option(Option)
           add_option(opt_str, ..., kwarg=val, ...)
        """
        if type(args[0]) in types.StringTypes:
            option = self.option_class(*args, **kwargs)
        elif len(args) == 1 and not kwargs:
            option = args[0]
            if not isinstance(option, Option):
                raise TypeError, "not an Option instance: %r" % option
        else:
            raise TypeError, "invalid arguments"

        self._check_conflict(option)

        self.option_list.append(option)
        option.container = self
        for opt in option._short_opts:
            self._short_opt[opt] = option
        for opt in option._long_opts:
            self._long_opt[opt] = option

        if option.dest is not None:     # option has a dest, we need a default
            if option.default is not NO_DEFAULT:
                self.defaults[option.dest] = option.default
            elif option.dest not in self.defaults:
                self.defaults[option.dest] = None

        return option
def add_option(self, *args, **kwargs):
        """add_option(Option)
           add_option(opt_str, ..., kwarg=val, ...)
        """
        if type(args[0]) in types.StringTypes:
            option = self.option_class(*args, **kwargs)
        elif len(args) == 1 and not kwargs:
            option = args[0]
            if not isinstance(option, Option):
                raise TypeError, "not an Option instance: %r" % option
        else:
            raise TypeError, "invalid arguments"

        self._check_conflict(option)

        self.option_list.append(option)
        option.container = self
        for opt in option._short_opts:
            self._short_opt[opt] = option
        for opt in option._long_opts:
            self._long_opt[opt] = option

        if option.dest is not None:     # option has a dest, we need a default
            if option.default is not NO_DEFAULT:
                self.defaults[option.dest] = option.default
            elif option.dest not in self.defaults:
                self.defaults[option.dest] = None

        return option
def add_option ( self , * args , * * kwargs ) : if type ( args [ 0 ] ) in types . StringTypes : option = self . option_class ( * args , * * kwargs ) elif len ( args ) == 1 and not kwargs : option = args [ 0 ] if not isinstance ( option , Option ) : raise TypeError , "not an Option instance: %r" % option else : raise TypeError , "invalid arguments" self . _check_conflict ( option ) self . option_list . append ( option ) option . container = self for opt in option . _short_opts : self . _short_opt [ opt ] = option for opt in option . _long_opts : self . _long_opt [ opt ] = option if option . dest is not None : # option has a dest, we need a default if option . default is not NO_DEFAULT : self . defaults [ option . dest ] = option . default elif option . dest not in self . defaults : self . defaults [ option . dest ] = None return option
add_option(Option)
           add_option(opt_str, ..., kwarg=val, ...)
add_option ( Option ) add_option ( opt_str ... kwarg = val ... )