| 703 | |
| 704 | |
| 705 | class ScriptsBase(object): |
| 706 | def __init__(self, |
| 707 | config=None, |
| 708 | side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER, |
| 709 | state=None): |
| 710 | self._config = config or self._Config() |
| 711 | self._side_effect_handler = side_effect_handler |
| 712 | self._state = state if state is not None else {} |
| 713 | |
| 714 | def _Description(self): |
| 715 | return None |
| 716 | |
| 717 | def _PrepareOptions(self, parser): |
| 718 | pass |
| 719 | |
| 720 | def _ProcessOptions(self, options): |
| 721 | return True |
| 722 | |
| 723 | def _Steps(self): # pragma: no cover |
| 724 | raise Exception("Not implemented.") |
| 725 | |
| 726 | def _Config(self): |
| 727 | return {} |
| 728 | |
| 729 | def MakeOptions(self, args=None): |
| 730 | parser = argparse.ArgumentParser(description=self._Description()) |
| 731 | parser.add_argument("-a", "--author", default="", |
| 732 | help="The author email used for code review.") |
| 733 | parser.add_argument("--dry-run", default=False, action="store_true", |
| 734 | help="Perform only read-only actions.") |
| 735 | parser.add_argument("--json-output", |
| 736 | help="File to write results summary to.") |
| 737 | parser.add_argument("-r", "--reviewer", default="", |
| 738 | help="The account name to be used for reviews.") |
| 739 | parser.add_argument("--tbr-reviewer", "--tbr", default="", |
| 740 | help="The account name to be used for TBR reviews.") |
| 741 | parser.add_argument("-s", "--step", |
| 742 | help="Specify the step where to start work. Default: 0.", |
| 743 | default=0, type=int) |
| 744 | parser.add_argument("--work-dir", |
| 745 | help=("Location where to bootstrap a working v8 " |
| 746 | "checkout.")) |
| 747 | self._PrepareOptions(parser) |
| 748 | |
| 749 | if args is None: # pragma: no cover |
| 750 | options = parser.parse_args() |
| 751 | else: |
| 752 | options = parser.parse_args(args) |
| 753 | |
| 754 | # Process common options. |
| 755 | if options.step < 0: # pragma: no cover |
| 756 | print("Bad step number %d" % options.step) |
| 757 | parser.print_help() |
| 758 | return None |
| 759 | |
| 760 | # Defaults for options, common to all scripts. |
| 761 | options.manual = getattr(options, "manual", True) |
| 762 | options.force = getattr(options, "force", False) |