Exemplo n.º 1
0
def parse_args(args: list) -> dict:
    """
    Create a parser for command line attributes and parses them
    :param args: the arguments to parse
    :return: parsed arguments
    """
    parser = SmartArgumentParser(
        description="Triggers some bug in listed programs",
        parents=[arguments.get_verbosity_parser()])
    plugin_parser = parser.add_subparsers(metavar="plugin")
    parser.add_argument("bugs",
                        nargs="+",
                        type=str,
                        help="one of {} or all".format(", ".join(PROGRAMS)),
                        metavar="bug",
                        choices=PROGRAMS + ["all"])

    register_for_trigger(parser=parser, subparser=plugin_parser)

    parsed_args = parser.parse_args(args)

    # noinspection PyUnresolvedReferences
    logging.getLogger().setLevel(parsed_args.logging_level)

    _bugs = parsed_args.bugs
    if "all" in _bugs:
        parsed_args.bugs = [
            program for program in PROGRAMS if os.path.exists(
                get_trigger_conf(program).get("install_directory"))
        ]
    else:
        for _ in _bugs:
            if _ not in PROGRAMS:
                parser.print_help()
                exit(PROGRAM_ARGUMENT_ERROR)

    return vars(parsed_args)
Exemplo n.º 2
0
 def setUp(self):
     self.argparser = SmartArgumentParser()
     self.subparser = self.argparser.add_subparsers()
     self.subparser.add_parser("test").set_defaults(test=2)
     self.argparser.add_argument("entries", nargs="+", type=int)