Beispiel #1
0
    def build_parser(available_choices_only=False):
        parser = CustomArgumentParser(description=PROGRAM_DESCRIPTION,
                                      formatter_class=CustomHelpFormatter)

        group = parser.add_mutually_exclusive_group()
        current_group = 0
        for option in traverse_options(OPTIONS + plugin_manager.get_options()):
            available_choices = option.pop("available_choices", option.get("choices"))
            if available_choices_only:
                option["choices"] = available_choices

            option_kwargs = dict(option)
            for key in ("group", "default", "name"):
                if key in option_kwargs:
                    del option_kwargs[key]

            if "group" in option:
                if current_group != option["group"]:
                    current_group = option["group"]
                    group = parser.add_mutually_exclusive_group()
                actions_container = group
            else:
                actions_container = parser

            # default is set to SUPPRESS to prevent arguments which were not specified on command line from being
            # added to namespace. This allows rebase-helper to determine which arguments are used with their
            # default value. This is later used for merging CLI arguments with config.
            actions_container.add_argument(*option["name"], action=CustomAction, default=argparse.SUPPRESS,
                                           actual_default=option.get("default"), **option_kwargs)

        return parser
Beispiel #2
0
    def build_parser():
        parser = CustomArgumentParser(description=PROGRAM_DESCRIPTION,
                                      formatter_class=CustomHelpFormatter)

        group = parser.add_mutually_exclusive_group()
        current_group = 0
        for option in traverse_options(OPTIONS):
            option_kwargs = dict(option)
            for key in ("group", "default", "name"):
                if key in option_kwargs:
                    del option_kwargs[key]

            if "group" in option:
                if current_group != option["group"]:
                    current_group = option["group"]
                    group = parser.add_mutually_exclusive_group()
                actions_container = group
            else:
                actions_container = parser

            # default is set to SUPPRESS to prevent arguments which were not specified on command line from being
            # added to namespace. This allows rebase-helper to determine which arguments are used with their
            # default value. This is later used for merging CLI arguments with config.
            actions_container.add_argument(
                *option["name"],
                action=CustomAction,
                default=argparse.SUPPRESS,
                actual_default=option.get("default"),
                **option_kwargs)

        return parser
Beispiel #3
0
    def merge(self, cli):
        self.config.update(vars(cli.args))

        for option in traverse_options(OPTIONS):
            args = [n.lstrip('-').replace('-', '_') for n in option['name'] if n.startswith('--')]
            if args:
                dest = args[0]

            if dest and dest not in self.config:
                self.config[dest] = option.get('default')
Beispiel #4
0
    def merge(self, cli):
        self.config.update(vars(cli.args))

        for option in traverse_options(OPTIONS + plugin_manager.get_options()):
            if 'dest' in option:
                dest = option['dest']
            else:
                args = [n.lstrip('-').replace('-', '_') for n in option['name'] if n.startswith('--')]
                if args:
                    dest = args[0]

            if dest and dest not in self.config:
                self.config[dest] = option.get('default')