blob: dad2475668dbac556aa7e0ce30e1d80cc3c5b1e2 [file] [log] [blame]
Alex Klein69c642e2023-02-16 14:47:55 -07001# 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
7TODO(skeleton): Rewrite file docblock.
8"""
Mike Frysinger93afe3e2023-09-05 14:18:52 -04009
Alex Klein69c642e2023-02-16 14:47:55 -070010import argparse
11from typing import List, Optional
12
13from chromite.lib import commandline
14
15
16def 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
27def _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
49def 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
58def 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 Frysingerd37fc3a2023-03-03 23:25:34 -050065 print(opts)