Skip to content

Commit d02956f

Browse files
Implementing output directory as an argument --output (#23)
* addin command argument --ouput xx.py --output /path/to/output/directory * seperate generated output with cleanedup output * ⚡️ Improve default output directory help message * ✨ Refactor function to simplify arguments passing Simplified argument passing in the function for generating C# classes.
1 parent aeaaccb commit d02956f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ dmypy.json
136136
src/_your_package_version.py
137137

138138
src/schemas/
139+
src/generated-dotnet-classes/

src/bo4egenerator/cli.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import os
88
import platform
9+
import shutil
910
from pathlib import Path
1011

1112
import typer
@@ -20,15 +21,22 @@
2021

2122

2223
@app.command()
23-
def main() -> None:
24+
def main(
25+
output: Path = typer.Option(
26+
Path.cwd() / "dotnet-classes", help="Output directory for the generated C# classes. default: dotnet-classes"
27+
)
28+
) -> None:
2429
"""
2530
It will use BO4E-Schema-Tool and
2631
generate C# classes from the BO4E schema files with help of Quicktype.
32+
33+
args:
34+
output (Path): Output directory for the generated C# classes.
2735
"""
2836
# Define the base directories
2937
project_root = Path.cwd() # Root directory of the project
3038
schemas_dir = project_root / "schemas"
31-
output_dir = project_root / "dotnet-classes"
39+
generated_output_dir = project_root / "generated-dotnet-classes"
3240

3341
# Determine the Quicktype executable path based on the operating system
3442
path_app_data = os.getenv("APPDATA")
@@ -40,11 +48,16 @@ def main() -> None:
4048
# Install BO4E-Schema-Tool and generate schemas
4149
running_bo4e_schema_tool(str(schemas_dir))
4250

43-
# Generate C# classes
44-
generate_csharp_classes(Path(project_root), Path(schemas_dir), Path(output_dir), quicktype_executable)
51+
# Generate C# classes from the schemas
52+
generate_csharp_classes(project_root, schemas_dir, generated_output_dir, quicktype_executable)
53+
54+
# Copy the generated files and subdirectories to the output directory
55+
if output.exists():
56+
shutil.rmtree(output) # Remove existing output directory if it exists
57+
shutil.copytree(generated_output_dir, output) # Copy the generated output to the final output directory
4558

4659
# Remove duplicate class and enum definitions
47-
process_directory(Path(output_dir))
60+
process_directory(output)
4861

4962

5063
def cli() -> None:

0 commit comments

Comments
 (0)