Skip to content

Commit a4038b8

Browse files
committed
Merge remote-tracking branch 'output-dir/cli-argument-output-dir'
2 parents f741d81 + 9bf6a97 commit a4038b8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

openapi_python_client/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(
5656
config: Config,
5757
custom_template_path: Optional[Path] = None,
5858
file_encoding: str = "utf-8",
59+
output_path: Optional[Path] = None,
5960
) -> None:
6061
self.openapi: GeneratorData = openapi
6162
self.meta: MetaType = meta
@@ -82,7 +83,7 @@ def __init__(
8283
)
8384

8485
self.project_name: str = config.project_name_override or f"{utils.kebab_case(openapi.title).lower()}-client"
85-
self.project_dir: Path = Path.cwd()
86+
self.project_dir: Path = Path.cwd() if output_path is None else Path(output_path).absolute()
8687
if meta != MetaType.NONE:
8788
self.project_dir /= self.project_name
8889

@@ -309,6 +310,7 @@ def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
309310
config: Config,
310311
custom_template_path: Optional[Path] = None,
311312
file_encoding: str = "utf-8",
313+
output_path: Optional[Path] = None,
312314
) -> Union[Project, GeneratorError]:
313315
data_dict = _get_document(url=url, path=path, timeout=config.http_timeout)
314316
if isinstance(data_dict, GeneratorError):
@@ -322,6 +324,7 @@ def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
322324
meta=meta,
323325
file_encoding=file_encoding,
324326
config=config,
327+
output_path=output_path
325328
)
326329

327330

@@ -333,6 +336,7 @@ def create_new_client(
333336
config: Config,
334337
custom_template_path: Optional[Path] = None,
335338
file_encoding: str = "utf-8",
339+
output_path: Optional[Path] = None,
336340
) -> Sequence[GeneratorError]:
337341
"""
338342
Generate the client library
@@ -347,6 +351,7 @@ def create_new_client(
347351
meta=meta,
348352
file_encoding=file_encoding,
349353
config=config,
354+
output_path=output_path
350355
)
351356
if isinstance(project, GeneratorError):
352357
return [project]
@@ -361,6 +366,7 @@ def update_existing_client(
361366
config: Config,
362367
custom_template_path: Optional[Path] = None,
363368
file_encoding: str = "utf-8",
369+
output_path: Optional[Path] = None,
364370
) -> Sequence[GeneratorError]:
365371
"""
366372
Update an existing client library
@@ -375,6 +381,7 @@ def update_existing_client(
375381
meta=meta,
376382
file_encoding=file_encoding,
377383
config=config,
384+
output_path=output_path
378385
)
379386
if isinstance(project, GeneratorError):
380387
return [project]

openapi_python_client/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def generate(
120120
meta: MetaType = _meta_option,
121121
file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"),
122122
config_path: Optional[pathlib.Path] = CONFIG_OPTION,
123+
output_path: Optional[pathlib.Path] = typer.Option(None, help="Set a path to store the api client"),
123124
fail_on_warning: bool = False,
124125
) -> None:
125126
"""Generate a new OpenAPI Client library"""
@@ -146,6 +147,7 @@ def generate(
146147
custom_template_path=custom_template_path,
147148
file_encoding=file_encoding,
148149
config=config,
150+
output_path=output_path,
149151
)
150152
handle_errors(errors, fail_on_warning)
151153

@@ -159,6 +161,7 @@ def update(
159161
meta: MetaType = _meta_option,
160162
file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"),
161163
config_path: Optional[pathlib.Path] = CONFIG_OPTION,
164+
output_path: Optional[pathlib.Path] = typer.Option(None, help="Set a path to store the api client"),
162165
fail_on_warning: bool = False,
163166
) -> None:
164167
"""Update an existing OpenAPI Client library
@@ -189,5 +192,6 @@ def update(
189192
custom_template_path=custom_template_path,
190193
file_encoding=file_encoding,
191194
config=config,
195+
output_path=output_path,
192196
)
193197
handle_errors(errors, fail_on_warning)

0 commit comments

Comments
 (0)