()
| 3117 | |
| 3118 | @staticmethod |
| 3119 | def parse_args(): |
| 3120 | args_parser = argparse.ArgumentParser( |
| 3121 | description="Applies OpenAPI spec to PyGithub GithubObject classes", |
| 3122 | formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 3123 | ) |
| 3124 | args_parser.add_argument( |
| 3125 | "--dry-run", default=False, action="store_true", help="Show prospect changes and do not modify any files" |
| 3126 | ) |
| 3127 | args_parser.add_argument( |
| 3128 | "--exit-code", default=False, action="store_true", help="Indicate changes via non-zeor exit code" |
| 3129 | ) |
| 3130 | args_parser.add_argument("--verbose", default=False, action="store_true", help="Provide more information") |
| 3131 | |
| 3132 | subparsers = args_parser.add_subparsers(dest="subcommand") |
| 3133 | fetch_parser = subparsers.add_parser("fetch") |
| 3134 | fetch_parser.add_argument( |
| 3135 | "api", |
| 3136 | help="Github API, e.g. api.github.com, ghec, ghes-3.15. See https://github.com/github/rest-api-description/tree/main/descriptions", |
| 3137 | ) |
| 3138 | fetch_parser.add_argument("--commit", help="Specific commit to fetch file from", nargs="?") |
| 3139 | fetch_parser.add_argument("api_version", help="Github API version date, e.g. 2022-11-28") |
| 3140 | fetch_parser.add_argument("spec", help="Github API OpenAPI spec file to be written") |
| 3141 | |
| 3142 | index_parser = subparsers.add_parser("index") |
| 3143 | index_parser.add_argument("--check-verbs", help="Check verbs in doc-string matches code", action="store_true") |
| 3144 | index_parser.add_argument("github_path", help="Path to PyGithub Python files") |
| 3145 | index_parser.add_argument("spec", help="Github API OpenAPI spec file", nargs="?") |
| 3146 | index_parser.add_argument("index_filename", help="Path of index file") |
| 3147 | |
| 3148 | suggest_parser = subparsers.add_parser("suggest") |
| 3149 | suggest_component_parsers = suggest_parser.add_subparsers(dest="component", required=True) |
| 3150 | suggest_paths_parser = suggest_component_parsers.add_parser("paths") |
| 3151 | suggest_paths_parser.add_argument("spec", help="Github API OpenAPI spec file") |
| 3152 | suggest_paths_parser.add_argument("index_filename", help="Path of index file") |
| 3153 | suggest_paths_parser.add_argument("class_name", help="Name of the class to get suggestions for", nargs="*") |
| 3154 | |
| 3155 | suggest_schemas_parser = suggest_component_parsers.add_parser("schemas") |
| 3156 | suggest_schemas_parser.add_argument( |
| 3157 | "--add", default=False, action="store_true", help="Add suggestions to source code" |
| 3158 | ) |
| 3159 | suggest_schemas_parser.add_argument("spec", help="Github API OpenAPI spec file") |
| 3160 | suggest_schemas_parser.add_argument("index_filename", help="Path of index file") |
| 3161 | suggest_schemas_parser.add_argument("class_name", help="Name of the class to get suggestions for", nargs="*") |
| 3162 | |
| 3163 | apply_parser = subparsers.add_parser("apply", description="Apply schema to source code") |
| 3164 | apply_parser.add_argument("--tests", help="Also apply spec to test files", action="store_true") |
| 3165 | apply_parser.add_argument( |
| 3166 | "--new-schemas", |
| 3167 | type=HandleNewSchemas, |
| 3168 | help="How to handle attributes that return schemas that are not implemented by any PyGithub: 'ignore', 'create-class' crates class implementation drafts, 'as-dict' return dict[str, Any]). Option 'create-class' does not support --dry-run.", |
| 3169 | choices=list(HandleNewSchemas), |
| 3170 | ) |
| 3171 | apply_parser.add_argument("github_path", help="Path to PyGithub Python files") |
| 3172 | apply_parser.add_argument("spec", help="Github API OpenAPI spec file") |
| 3173 | apply_parser.add_argument("index_filename", help="Path of index file") |
| 3174 | apply_parser.add_argument("class_name", help="PyGithub GithubObject class name", nargs="*") |
| 3175 | |
| 3176 | create_parser = subparsers.add_parser("create", description="Create PyGithub classes and methods") |
no test coverage detected