add_option(Option) add_option(opt_str, ..., kwarg=val, ...)
(self, *args, **kwargs)
| 983 | c_option.container.option_list.remove(c_option) |
| 984 | |
| 985 | def add_option(self, *args, **kwargs): |
| 986 | """add_option(Option) |
| 987 | add_option(opt_str, ..., kwarg=val, ...) |
| 988 | """ |
| 989 | if isinstance(args[0], str): |
| 990 | option = self.option_class(*args, **kwargs) |
| 991 | elif len(args) == 1 and not kwargs: |
| 992 | option = args[0] |
| 993 | if not isinstance(option, Option): |
| 994 | raise TypeError("not an Option instance: %r" % option) |
| 995 | else: |
| 996 | raise TypeError("invalid arguments") |
| 997 | |
| 998 | self._check_conflict(option) |
| 999 | |
| 1000 | self.option_list.append(option) |
| 1001 | option.container = self |
| 1002 | for opt in option._short_opts: |
| 1003 | self._short_opt[opt] = option |
| 1004 | for opt in option._long_opts: |
| 1005 | self._long_opt[opt] = option |
| 1006 | |
| 1007 | if option.dest is not None: # option has a dest, we need a default |
| 1008 | if option.default is not NO_DEFAULT: |
| 1009 | self.defaults[option.dest] = option.default |
| 1010 | elif option.dest not in self.defaults: |
| 1011 | self.defaults[option.dest] = None |
| 1012 | |
| 1013 | return option |
| 1014 | |
| 1015 | def add_options(self, option_list): |
| 1016 | for option in option_list: |
no test coverage detected