|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | from __future__ import annotations |
3 | 3 |
|
| 4 | +import argparse |
4 | 5 | import shutil |
5 | 6 | import subprocess |
6 | 7 | import sys |
@@ -28,13 +29,32 @@ def download_file(url: str, target: Path) -> None: |
28 | 29 | run_command(["wget", "-O", str(target), url]) |
29 | 30 |
|
30 | 31 |
|
| 32 | +def parse_args() -> argparse.Namespace: |
| 33 | + """Parse command line arguments.""" |
| 34 | + parser = argparse.ArgumentParser(description="Generate Together API client") |
| 35 | + parser.add_argument( |
| 36 | + "--skip-spec-download", |
| 37 | + action="store_true", |
| 38 | + help="Skip downloading the OpenAPI spec file", |
| 39 | + ) |
| 40 | + return parser.parse_args() |
| 41 | + |
| 42 | + |
31 | 43 | def main() -> None: |
32 | | - # Download OpenAPI spec |
| 44 | + args = parse_args() |
33 | 45 | spec_file = Path(__file__).parent / "openapi.yaml" |
34 | | - download_file(OPENAPI_SPEC_URL, spec_file) |
35 | 46 |
|
36 | | - # Run formatter on the spec for better merge conflict handling |
37 | | - run_command(["npx", "-y", "prettier", "--write", str(spec_file)]) |
| 47 | + # Download OpenAPI spec if not skipped |
| 48 | + if not args.skip_spec_download: |
| 49 | + download_file(OPENAPI_SPEC_URL, spec_file) |
| 50 | + # Run formatter on the spec for better merge conflict handling |
| 51 | + run_command(["npx", "-y", "prettier", "--write", str(spec_file)]) |
| 52 | + elif not spec_file.exists(): |
| 53 | + print( |
| 54 | + "Error: OpenAPI spec file not found and download was skipped", |
| 55 | + file=sys.stderr, |
| 56 | + ) |
| 57 | + sys.exit(1) |
38 | 58 |
|
39 | 59 | # Download generator if needed |
40 | 60 | download_file(GENERATOR_JAR_URL, GENERATOR_JAR) |
|
0 commit comments