(argv: list[str] | None = None)
| 31 | |
| 32 | |
| 33 | def main(argv: list[str] | None = None) -> int: |
| 34 | from update_lib import ( |
| 35 | apply_patches, |
| 36 | extract_patches, |
| 37 | patches_from_json, |
| 38 | patches_to_json, |
| 39 | ) |
| 40 | |
| 41 | parser = argparse.ArgumentParser( |
| 42 | description=__doc__, |
| 43 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 44 | ) |
| 45 | |
| 46 | patches_group = parser.add_mutually_exclusive_group(required=True) |
| 47 | patches_group.add_argument( |
| 48 | "-p", |
| 49 | "--patches", |
| 50 | type=pathlib.Path, |
| 51 | help="File path to file containing patches in a JSON format", |
| 52 | ) |
| 53 | patches_group.add_argument( |
| 54 | "--from", |
| 55 | dest="gather_from", |
| 56 | type=pathlib.Path, |
| 57 | help="File to gather patches from", |
| 58 | ) |
| 59 | |
| 60 | group = parser.add_mutually_exclusive_group(required=False) |
| 61 | group.add_argument( |
| 62 | "--to", |
| 63 | type=pathlib.Path, |
| 64 | help="File to apply patches to", |
| 65 | ) |
| 66 | group.add_argument( |
| 67 | "--show-patches", |
| 68 | action="store_true", |
| 69 | help="Show the patches and exit", |
| 70 | ) |
| 71 | |
| 72 | parser.add_argument( |
| 73 | "-o", |
| 74 | "--output", |
| 75 | default="-", |
| 76 | help="Output file. Set to '-' for stdout", |
| 77 | ) |
| 78 | |
| 79 | args = parser.parse_args(argv) |
| 80 | |
| 81 | # Validate required arguments |
| 82 | if args.to is None and not args.show_patches: |
| 83 | parser.error("--to or --show-patches is required") |
| 84 | |
| 85 | try: |
| 86 | if args.patches: |
| 87 | patches = patches_from_json(json.loads(args.patches.read_text())) |
| 88 | else: |
| 89 | patches = extract_patches(args.gather_from.read_text()) |
| 90 |
no test coverage detected