Skip to content

Commit 8ddcb32

Browse files
🐛 Default to save the document if source path is remote.
1 parent 9268f4b commit 8ddcb32

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/lapidary/render/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ def app(verbose: bool) -> None:
1919
@click.argument('document')
2020
@click.argument('project_root', type=click.Path(path_type=Path, exists=False, file_okay=False, dir_okay=True))
2121
@click.argument('package_name')
22-
@click.option('--save/--no-save', help='Copy the document in the project', default=False)
22+
@click.option(
23+
'--save/--no-save',
24+
help="Copy the document in the project. The default is to save if it's a remote path",
25+
default=None,
26+
)
2327
def init(
2428
document: str,
2529
project_root: Path,
2630
package_name: str,
27-
save: bool = False,
31+
save: bool | None,
2832
):
2933
"""Initialize a new project.
3034

src/lapidary/render/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def init_project(
1818
document_path: str,
1919
project_root: Path,
2020
package_name: str,
21-
save_document: bool,
21+
save_document: bool | None,
2222
) -> None:
2323
"""Create project directory and pyproject file, download or copy the OpenAPI document"""
2424

@@ -29,6 +29,10 @@ def init_project(
2929

3030
document_handler = document_handler_for(Path(), document_path)
3131

32+
if save_document is None and document_handler.is_url:
33+
# default is save if document is remote
34+
save_document = True
35+
3236
if save_document:
3337
document_root = Path('lapidary/openapi')
3438
target_dir = project_root / document_root
@@ -49,7 +53,7 @@ def init_project(
4953
else:
5054
config_document_path = document_path
5155
else:
52-
config_document_path = None
56+
config_document_path = document_path
5357

5458
config = Config(
5559
# if path is not URL and not saving the file

tests/test_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pathlib import Path
22

3-
import pytest
43
from click.testing import CliRunner
54

65
from lapidary.render.config import load_config
@@ -54,4 +53,4 @@ def test_init_url_saves_origin(tmp_path: Path) -> None:
5453

5554
config = load_config(output)
5655
assert str(config.origin) == source
57-
assert config.document_path is None
56+
assert config.document_path == 'lapidary/openapi/openapi.json'

0 commit comments

Comments
 (0)