Alex Klein | 69c642e | 2023-02-16 14:47:55 -0700 | [diff] [blame] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Skeleton for new scripts or to allow quickly implementing temp scripts. |
| 6 | |
| 7 | TODO(skeleton): Rewrite file docblock. |
| 8 | """ |
Mike Frysinger | 93afe3e | 2023-09-05 14:18:52 -0400 | [diff] [blame^] | 9 | |
Alex Klein | 69c642e | 2023-02-16 14:47:55 -0700 | [diff] [blame] | 10 | import argparse |
| 11 | from typing import List, Optional |
| 12 | |
| 13 | from chromite.lib import commandline |
| 14 | |
| 15 | |
| 16 | def get_parser() -> commandline.ArgumentParser: |
| 17 | """Build the argument parser.""" |
| 18 | parser = commandline.ArgumentParser(description=__doc__) |
| 19 | |
| 20 | # TODO(skeleton): Delete. |
| 21 | _add_local_script_args(parser) |
| 22 | # TODO(skeleton): Add arguments. |
| 23 | |
| 24 | return parser |
| 25 | |
| 26 | |
| 27 | def _add_local_script_args(parser: commandline.ArgumentParser) -> None: |
| 28 | """Add a bunch of commonly used arguments to the parser. |
| 29 | |
| 30 | This is for hacking up quick, local scripts, and not intended to be kept |
| 31 | when used as a skeleton for a permanent script. |
| 32 | TODO(skeleton): Delete function. |
| 33 | """ |
| 34 | parser.add_argument( |
| 35 | "-b", "--board", "--build-target", help="Build target name." |
| 36 | ) |
| 37 | parser.add_argument("--chroot", type="path", help="Chroot path.") |
| 38 | parser.add_argument("--input", type="path", help="Input path.") |
| 39 | parser.add_argument("--output", type="path", help="Output path.") |
| 40 | parser.add_argument("-p", "--package", help="Package.") |
| 41 | parser.add_argument( |
| 42 | "--sdk", action="store_true", default=False, help="For the SDK." |
| 43 | ) |
| 44 | parser.add_argument("--sysroot", type="path", help="Sysroot path.") |
| 45 | |
| 46 | parser.add_argument("packages", nargs="*", default=[]) |
| 47 | |
| 48 | |
| 49 | def parse_arguments(argv: List) -> argparse.Namespace: |
| 50 | """Parse and validate arguments.""" |
| 51 | parser = get_parser() |
| 52 | opts = parser.parse_args(argv) |
| 53 | |
| 54 | opts.Freeze() |
| 55 | return opts |
| 56 | |
| 57 | |
| 58 | def main(argv: Optional[List[str]]) -> Optional[int]: |
| 59 | """Main.""" |
| 60 | # Uncomment for inside-only scripts. |
| 61 | # TODO(skeleton) Delete or uncomment. |
| 62 | # commandline.RunInsideChroot() |
| 63 | |
| 64 | opts = parse_arguments(argv) |
Mike Frysinger | d37fc3a | 2023-03-03 23:25:34 -0500 | [diff] [blame] | 65 | print(opts) |