|
| 1 | +import argparse |
| 2 | +from typing import List, Optional |
| 3 | + |
| 4 | +from build_swift.build_swift.constants import SWIFT_SOURCE_ROOT |
| 5 | + |
| 6 | + |
| 7 | +class CliArguments(argparse.Namespace): |
| 8 | + clone: bool |
| 9 | + clone_with_ssh: bool |
| 10 | + skip_history: bool |
| 11 | + skip_tags: bool |
| 12 | + skip_repository_list: List[str] |
| 13 | + all_repositories: bool |
| 14 | + scheme: Optional[str] |
| 15 | + reset_to_remote: bool |
| 16 | + clean: bool |
| 17 | + stash: bool |
| 18 | + configs: List[str] |
| 19 | + github_comment: Optional[str] |
| 20 | + dump_hashes: bool |
| 21 | + dump_hashes_config: Optional[str] |
| 22 | + tag: Optional[str] |
| 23 | + match_timestamp: bool |
| 24 | + n_processes: int |
| 25 | + source_root: str |
| 26 | + use_submodules: bool |
| 27 | + verbose: bool |
| 28 | + |
| 29 | + @staticmethod |
| 30 | + def parse_args() -> "CliArguments": |
| 31 | + parser = argparse.ArgumentParser( |
| 32 | + formatter_class=argparse.RawDescriptionHelpFormatter, |
| 33 | + description=""" |
| 34 | +By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM |
| 35 | +repositories. |
| 36 | + """, |
| 37 | + ) |
| 38 | + parser.add_argument( |
| 39 | + "--clone", |
| 40 | + help="obtain sources for Swift and related projects", |
| 41 | + action="store_true", |
| 42 | + ) |
| 43 | + parser.add_argument( |
| 44 | + "--clone-with-ssh", |
| 45 | + help="Obtain sources for Swift and related projects via SSH", |
| 46 | + action="store_true", |
| 47 | + ) |
| 48 | + parser.add_argument( |
| 49 | + "--skip-history", |
| 50 | + help="Skip histories when obtaining sources", |
| 51 | + action="store_true", |
| 52 | + ) |
| 53 | + parser.add_argument( |
| 54 | + "--skip-tags", help="Skip tags when obtaining sources", action="store_true" |
| 55 | + ) |
| 56 | + parser.add_argument( |
| 57 | + "--skip-repository", |
| 58 | + metavar="DIRECTORY", |
| 59 | + default=[], |
| 60 | + help="Skip the specified repository", |
| 61 | + dest="skip_repository_list", |
| 62 | + action="append", |
| 63 | + ) |
| 64 | + parser.add_argument( |
| 65 | + "--all-repositories", |
| 66 | + help="""Includes repositories not required for current platform. |
| 67 | + This will not override '--skip-repositories'""", |
| 68 | + action="store_true", |
| 69 | + ) |
| 70 | + parser.add_argument( |
| 71 | + "--scheme", |
| 72 | + help='Use branches from the specified branch-scheme. A "branch-scheme"' |
| 73 | + " is a list of (repo, branch) pairs.", |
| 74 | + metavar="BRANCH-SCHEME", |
| 75 | + ) |
| 76 | + parser.add_argument( |
| 77 | + "--reset-to-remote", |
| 78 | + help="Reset each branch to the remote state.", |
| 79 | + action="store_true", |
| 80 | + ) |
| 81 | + parser.add_argument( |
| 82 | + "--clean", |
| 83 | + help="""Delete tracked and untracked changes, ignored files, and abort |
| 84 | + an ongoing rebase, if any, before updating a repository.""", |
| 85 | + action="store_true", |
| 86 | + ) |
| 87 | + parser.add_argument( |
| 88 | + "--stash", |
| 89 | + help="""Stash tracked and untracked changes, delete ignored files, and |
| 90 | + abort an ongoing rebase, if any, before updating a repository.""", |
| 91 | + action="store_true", |
| 92 | + ) |
| 93 | + parser.add_argument( |
| 94 | + "--config", |
| 95 | + help="""The configuration file to use. Can be specified multiple times, |
| 96 | + each config will be merged together with a 'last-wins' strategy. |
| 97 | + Overwriting branch-schemes is not allowed.""", |
| 98 | + action="append", |
| 99 | + default=[], |
| 100 | + dest="configs", |
| 101 | + ) |
| 102 | + parser.add_argument( |
| 103 | + "--github-comment", |
| 104 | + help="""Check out related pull requests referenced in the given |
| 105 | + free-form GitHub-style comment.""", |
| 106 | + metavar="GITHUB-COMMENT", |
| 107 | + ) |
| 108 | + parser.add_argument( |
| 109 | + "--dump-hashes", |
| 110 | + action="store_true", |
| 111 | + help="Dump the git hashes of all repositories being tracked", |
| 112 | + ) |
| 113 | + parser.add_argument( |
| 114 | + "--dump-hashes-config", |
| 115 | + help="Dump the git hashes of all repositories packaged into " |
| 116 | + "update-checkout-config.json", |
| 117 | + metavar="BRANCH-SCHEME-NAME", |
| 118 | + ) |
| 119 | + parser.add_argument( |
| 120 | + "--tag", |
| 121 | + help="""Check out each repository to the specified tag.""", |
| 122 | + metavar="TAG-NAME", |
| 123 | + ) |
| 124 | + parser.add_argument( |
| 125 | + "--match-timestamp", |
| 126 | + help="Check out adjacent repositories to match timestamp of " |
| 127 | + " current swift checkout.", |
| 128 | + action="store_true", |
| 129 | + ) |
| 130 | + parser.add_argument( |
| 131 | + "-j", |
| 132 | + "--jobs", |
| 133 | + type=int, |
| 134 | + help="Number of threads to run at once", |
| 135 | + default=0, |
| 136 | + dest="n_processes", |
| 137 | + ) |
| 138 | + parser.add_argument( |
| 139 | + "--source-root", |
| 140 | + help="The root directory to checkout repositories", |
| 141 | + default=SWIFT_SOURCE_ROOT, |
| 142 | + ) |
| 143 | + parser.add_argument( |
| 144 | + "--use-submodules", |
| 145 | + help="Checkout repositories as git submodules.", |
| 146 | + action="store_true", |
| 147 | + ) |
| 148 | + parser.add_argument( |
| 149 | + "-v", |
| 150 | + "--verbose", |
| 151 | + help="Increases the script's verbosity.", |
| 152 | + action="store_true", |
| 153 | + ) |
| 154 | + return parser.parse_args() |
0 commit comments