|
2 | 2 | import re |
3 | 3 | from typing import Annotated |
4 | 4 |
|
| 5 | +import requests |
| 6 | +import rich |
5 | 7 | import typer |
6 | 8 | from openapi_core import OpenAPI |
| 9 | +from rich.markdown import Markdown |
7 | 10 |
|
8 | 11 | from cli.client_gen.module_mapping import update_module_mapping |
9 | 12 | from cli.client_gen.resource_packages import resources_to_package_directory |
10 | 13 | from cli.client_gen.schema_packages import schemas_to_package_directory |
| 14 | +from cli.client_gen.utils import bump_patch_version |
11 | 15 |
|
12 | 16 | REPO_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
13 | 17 | SPEC_FILE = os.path.join(REPO_ROOT, 'dialpad_api_spec.json') |
@@ -35,7 +39,7 @@ def reformat_spec(): |
35 | 39 | with open(SPEC_FILE, 'w') as f: |
36 | 40 | f.write(spec_file_contents) |
37 | 41 |
|
38 | | - typer.echo(f"Reformatted OpenAPI spec at '{SPEC_FILE}'") |
| 42 | + rich.print(Markdown(f"Reformatted OpenAPI spec at `{SPEC_FILE}`")) |
39 | 43 |
|
40 | 44 |
|
41 | 45 | @app.command('update-resource-module-mapping') |
@@ -64,6 +68,51 @@ def generate_client(): |
64 | 68 | # Write the generated resource modules to the client directory |
65 | 69 | resources_to_package_directory(open_api_spec.spec, os.path.join(CLIENT_DIR, 'resources')) |
66 | 70 |
|
| 71 | +@app.command('interactive-update') |
| 72 | +def interactive_update(): |
| 73 | + """The one-stop-shop for updating the Dialpad client with the latest dialpad api spec.""" |
| 74 | + |
| 75 | + # Start by printing an overview of what this command will do, and wait for user confirmation |
| 76 | + with open(os.path.join(REPO_ROOT, 'cli', 'interactive_update_overview.md'), 'r') as f: |
| 77 | + overview_content = f.read() |
| 78 | + |
| 79 | + rich.print(Markdown(overview_content)) |
| 80 | + |
| 81 | + if not typer.confirm("Do you want to proceed with the update?"): |
| 82 | + rich.print(Markdown("Update cancelled by user.")) |
| 83 | + raise typer.Exit(0) |
| 84 | + |
| 85 | + api_spec_url = 'https://dialpad.com/static/openapi/platform-v1.0.json' |
| 86 | + rich.print(Markdown(f"Fetching OpenAPI spec from `{api_spec_url}`...")) |
| 87 | + |
| 88 | + response = requests.get(api_spec_url) |
| 89 | + if response.status_code == 200: |
| 90 | + with open(SPEC_FILE, 'wb') as f: |
| 91 | + f.write(response.content) |
| 92 | + rich.print(Markdown(f"Downloaded OpenAPI spec to `{SPEC_FILE}`")) |
| 93 | + else: |
| 94 | + rich.print(Markdown(f"Failed to download OpenAPI spec: `{response.status_code}`")) |
| 95 | + raise typer.Exit(1) |
| 96 | + |
| 97 | + reformat_spec() |
| 98 | + update_resource_module_mapping(interactive=True) |
| 99 | + generate_client() |
| 100 | + new_version_str = bump_patch_version() |
| 101 | + |
| 102 | + rich.print("\n") |
| 103 | + rich.print(Markdown(f"Bumped version to `{new_version_str}` 🎉")) |
| 104 | + rich.print(Markdown('\n'.join([ |
| 105 | + 'Recommended next steps:', |
| 106 | + '- Review the changes with `git diff`', |
| 107 | + '- Run the test suite with `uv run pytest`', |
| 108 | + ]))) |
| 109 | + rich.print("\n") |
| 110 | + rich.print(Markdown('\n'.join([ |
| 111 | + 'If everything looks good, then you can tag and push to publish the new version to PyPI:', |
| 112 | + f'- `git tag -a "v{new_version_str}" -m "Release version {new_version_str}"`', |
| 113 | + f'- `git push origin "v{new_version_str}"`', |
| 114 | + ]))) |
| 115 | + |
67 | 116 |
|
68 | 117 | if __name__ == '__main__': |
69 | 118 | app() |
0 commit comments