def _create_action_parser( cmd: plug.cli.Command, action: categorization.Action, is_category_action: bool, parsers_mapping: dict, subparsers: argparse._SubParsersAction, parents: List[argparse.ArgumentParser], ): settings = cmd.__settings__ ext_parser = (parsers_mapping.get(action.category) or subparsers).add_parser( action.name, help=settings.help, description=settings.description, parents=parents, formatter_class=argparse_ext.OrderedFormatter, ) try: argparse_ext.add_debug_args(ext_parser) except argparse.ArgumentError: pass _add_metainfo_args( ext_parser=ext_parser, action=action, cmd=cmd, is_category_action=is_category_action, ) return ext_parser
def _add_config_parsers( base_parser, template_org_parser, add_parser, get_default: Callable[[str], str], ): show_config = add_parser( plug.cli.CoreCommand.config.show, help="show the configuration file", description=( "Show the contents of the configuration file. If no configuration " "file can be found, show the path where repobee expectes to find " "it."), formatter_class=argparse_ext.OrderedFormatter, ) show_config.add_argument( "--secrets", help="show secrets in the config file that are otherwise sanitized", action="store_true", ) argparse_ext.add_debug_args(show_config) verify = add_parser( plug.cli.CoreCommand.config.verify, help="verify core settings", description="Verify core settings by trying various API requests.", parents=[base_parser, template_org_parser], formatter_class=argparse_ext.OrderedFormatter, ) _add_students_file_arg(verify, get_default)
def _create_base_parsers(get_default: Callable[[str], str]): """Create the base parsers.""" def configured(arg_name): return get_default(arg_name) is not None def api_requires(arg_name): return arg_name in plug.manager.hook.api_init_requires() # API args help sections user_help = "your username" org_name_help = "name of the target organization" base_url_help = ( "Base url to a platform API. Must be HTTPS. For example, with " "github.com, the base url is https://api.github.com, and with " "GitHub enterprise, the url is https://<ENTERPRISE_HOST>/api/v3") token_help = "access token for the platform instance" # other configurable args help sections # these should not be checked against the api_requires function template_org_help = ( "name of the organization containing the template repos " "(defaults to the same value as `-o|--org-name`)") base_parser = argparse_ext.RepobeeParser(is_core_command=True, add_help=False) base_parser.add_argument( "-u", "--user", help=user_help, type=str, required=not configured("user") and api_requires("user"), default=get_default("user"), ) base_parser.add_argument( "-o", "--org-name", help=org_name_help, type=str, required=not configured("org_name") and api_requires("org_name"), default=get_default("org_name"), ) base_parser.add_argument( "--bu", "--base-url", help=base_url_help, type=str, required=not configured("base_url") and api_requires("base_url"), default=get_default("base_url"), dest="base_url", ) base_parser.add_argument( "-t", "--token", help=token_help, type=str, required=not configured("token") and api_requires("token"), default=get_default("token"), ) argparse_ext.add_debug_args(base_parser) # base parser for when student lists are involved base_student_parser = argparse_ext.RepobeeParser(is_core_command=True, add_help=False) students = base_student_parser.add_argument_group( "core").add_mutually_exclusive_group( required=not configured("students_file")) _add_students_file_arg(students, get_default) students.add_argument( "-s", "--students", help="One or more whitespace separated student usernames.", type=str, nargs="+", ) template_org_parser = argparse_ext.RepobeeParser(is_core_command=True, add_help=False) template_org_parser.add_argument( "--to", "--template-org-name", help=template_org_help, default=get_default("template_org_name"), dest="template_org_name", ) return (base_parser, base_student_parser, template_org_parser)