| Joe Onorato | 7cf6f97 | 2022-05-11 21:39:57 -0700 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # |
| 3 | # Copyright (C) 2022 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import argparse |
| 18 | import sys |
| 19 | |
| 20 | def _parse_arguments(argv): |
| 21 | argv = argv[1:] |
| 22 | """Return an argparse options object.""" |
| 23 | # Top-level parser |
| 24 | parser = argparse.ArgumentParser(prog=".inner_build") |
| 25 | |
| 26 | parser.add_argument("--out_dir", action="store", required=True, |
| 27 | help="root of the output directory for this inner tree's API contributions") |
| 28 | |
| 29 | parser.add_argument("--api_domain", action="append", required=True, |
| 30 | help="which API domains are to be built in this inner tree") |
| 31 | |
| 32 | subparsers = parser.add_subparsers(required=True, dest="command", |
| 33 | help="subcommands") |
| 34 | |
| 35 | # inner_build describe command |
| 36 | describe_parser = subparsers.add_parser("describe", |
| 37 | help="describe the capabilities of this inner tree's build system") |
| 38 | |
| 39 | # create the parser for the "b" command |
| 40 | export_parser = subparsers.add_parser("export_api_contributions", |
| 41 | help="export the API contributions of this inner tree") |
| 42 | |
| Joe Onorato | c358956 | 2022-05-13 12:10:23 -0700 | [diff] [blame] | 43 | # create the parser for the "b" command |
| 44 | export_parser = subparsers.add_parser("analyze", |
| 45 | help="main build analysis for this inner tree") |
| 46 | |
| Joe Onorato | 7cf6f97 | 2022-05-11 21:39:57 -0700 | [diff] [blame] | 47 | # Parse the arguments |
| 48 | return parser.parse_args(argv) |
| 49 | |
| 50 | |
| 51 | class Commands(object): |
| 52 | def Run(self, argv): |
| 53 | """Parse the command arguments and call the corresponding subcommand method on |
| 54 | this object. |
| 55 | |
| 56 | Throws AttributeError if the method for the command wasn't found. |
| 57 | """ |
| 58 | args = _parse_arguments(argv) |
| 59 | return getattr(self, args.command)(args) |
| 60 | |