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