Skip to content

feat: CLI option to define output directory #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion openapi_python_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
config: Config,
custom_template_path: Optional[Path] = None,
file_encoding: str = "utf-8",
output_path: Optional[Path] = None,
) -> None:
self.openapi: GeneratorData = openapi
self.meta: MetaType = meta
Expand All @@ -78,7 +79,7 @@ def __init__(
)

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

Expand Down Expand Up @@ -300,6 +301,7 @@ def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
config: Config,
custom_template_path: Optional[Path] = None,
file_encoding: str = "utf-8",
output_path: Optional[Path] = None,
) -> Union[Project, GeneratorError]:
data_dict = _get_document(url=url, path=path)
if isinstance(data_dict, GeneratorError):
Expand All @@ -313,6 +315,7 @@ def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
meta=meta,
file_encoding=file_encoding,
config=config,
output_path=output_path
)


Expand All @@ -324,6 +327,7 @@ def create_new_client(
config: Config,
custom_template_path: Optional[Path] = None,
file_encoding: str = "utf-8",
output_path: Optional[Path] = None,
) -> Sequence[GeneratorError]:
"""
Generate the client library
Expand All @@ -338,6 +342,7 @@ def create_new_client(
meta=meta,
file_encoding=file_encoding,
config=config,
output_path=output_path
)
if isinstance(project, GeneratorError):
return [project]
Expand All @@ -352,6 +357,7 @@ def update_existing_client(
config: Config,
custom_template_path: Optional[Path] = None,
file_encoding: str = "utf-8",
output_path: Optional[Path] = None,
) -> Sequence[GeneratorError]:
"""
Update an existing client library
Expand All @@ -366,6 +372,7 @@ def update_existing_client(
meta=meta,
file_encoding=file_encoding,
config=config,
output_path=output_path
)
if isinstance(project, GeneratorError):
return [project]
Expand Down
4 changes: 4 additions & 0 deletions openapi_python_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def generate(
meta: MetaType = _meta_option,
file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"),
config_path: Optional[pathlib.Path] = CONFIG_OPTION,
output_path: Optional[pathlib.Path] = typer.Option(None, help="Set a path to store the api client"),
fail_on_warning: bool = False,
) -> None:
"""Generate a new OpenAPI Client library"""
Expand All @@ -146,6 +147,7 @@ def generate(
custom_template_path=custom_template_path,
file_encoding=file_encoding,
config=config,
output_path=output_path,
)
handle_errors(errors, fail_on_warning)

Expand All @@ -159,6 +161,7 @@ def update(
meta: MetaType = _meta_option,
file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"),
config_path: Optional[pathlib.Path] = CONFIG_OPTION,
output_path: Optional[pathlib.Path] = typer.Option(None, help="Set a path to store the api client"),
fail_on_warning: bool = False,
) -> None:
"""Update an existing OpenAPI Client library
Expand Down Expand Up @@ -189,5 +192,6 @@ def update(
custom_template_path=custom_template_path,
file_encoding=file_encoding,
config=config,
output_path=output_path,
)
handle_errors(errors, fail_on_warning)