diff --git a/pyproject.toml b/pyproject.toml index 8ca18f8..4c82850 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,13 +16,18 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] -dependencies = [] # add all the dependencies here +dependencies = [ + "typer", +] # add all the dependencies here dynamic = ["readme", "version"] [project.urls] Changelog = "https://github.com/bo4e/BO4E-CLI/releases" Homepage = "https://github.com/bo4e/BO4E-CLI" +[project.scripts] +bo4e = "bo4e_cli.__main__" + [tool.black] line-length = 120 target_version = ["py311", "py312"] diff --git a/src/bo4e_cli/__main__.py b/src/bo4e_cli/__main__.py new file mode 100644 index 0000000..c7797a4 --- /dev/null +++ b/src/bo4e_cli/__main__.py @@ -0,0 +1,4 @@ +from bo4e_cli.commands.entry import app + +if __name__ == "__main__": + app() diff --git a/src/bo4e_cli/commands/__init__.py b/src/bo4e_cli/commands/__init__.py new file mode 100644 index 0000000..2e2d53f --- /dev/null +++ b/src/bo4e_cli/commands/__init__.py @@ -0,0 +1,7 @@ +from .diff import sub_app_diff +from .edit import edit +from .entry import app +from .generate import generate +from .pull import pull + +app.add_typer(sub_app_diff, name="diff") diff --git a/src/bo4e_cli/commands/diff.py b/src/bo4e_cli/commands/diff.py new file mode 100644 index 0000000..5e7455b --- /dev/null +++ b/src/bo4e_cli/commands/diff.py @@ -0,0 +1,21 @@ +from pathlib import Path +from typing import Annotated, Optional + +import typer + +sub_app_diff = typer.Typer() + + +@sub_app_diff.command("schemas") +def diff_schemas( + *, + input_dir_base: Annotated[Path, typer.Argument()], + input_dir_comp: Annotated[Path, typer.Argument()], + output_file: Annotated[Path, typer.Option(help="The JSON-file to save the differences to.", show_default=False)], +): + """ + Compare the JSON-schemas in the two input directories and save the differences to the output file. + The output file will contain the differences in JSON-format. It will also contain information about the + compared versions. + """ + pass diff --git a/src/bo4e_cli/commands/edit.py b/src/bo4e_cli/commands/edit.py new file mode 100644 index 0000000..0721aad --- /dev/null +++ b/src/bo4e_cli/commands/edit.py @@ -0,0 +1,34 @@ +from pathlib import Path +from typing import Annotated, Optional + +import typer + +from bo4e_cli.commands.entry import app + + +@app.command() +def edit( + *, + input_dir: Annotated[Path, typer.Option(help="The directory to read the JSON-schemas from.", show_default=False)], + output_dir: Annotated[ + Path, typer.Option(help="The directory to save the edited JSON-schemas to.", show_default=False) + ], + config: Annotated[ + Optional[Path], typer.Option(help="The configuration file to use for editing the JSON-schemas.") + ] = None, + set_default_version: Annotated[ + bool, + typer.Option( + help="Automatically set or overrides the default version for '_version' fields with the version from " + ".version file. This is especially useful if you want to define additional models which should " + "always have the correct version." + ), + ] = True, + clear_output: Annotated[bool, typer.Option(help="Clear the output directory before saving the schemas.")] = True, +): + """ + Edit the JSON-schemas in the input directory and save the edited schemas to the output directory. + The schemas in the input directory won't be changed. If no configuration file is provided, the schemas will be + copied to the output directory unchanged. + """ + pass diff --git a/src/bo4e_cli/commands/entry.py b/src/bo4e_cli/commands/entry.py new file mode 100644 index 0000000..e5ac6c0 --- /dev/null +++ b/src/bo4e_cli/commands/entry.py @@ -0,0 +1,3 @@ +import typer + +app = typer.Typer() diff --git a/src/bo4e_cli/commands/generate.py b/src/bo4e_cli/commands/generate.py new file mode 100644 index 0000000..91eec77 --- /dev/null +++ b/src/bo4e_cli/commands/generate.py @@ -0,0 +1,34 @@ +from enum import StrEnum +from pathlib import Path +from typing import Annotated, Optional + +import typer + +from bo4e_cli.commands.entry import app + + +class GenerateType(StrEnum): + """ + A custom type for the generate command. + """ + + PYTHON_PYDANTIC_V1 = "python-pydantic-v1" + PYTHON_PYDANTIC_V2 = "python-pydantic-v2" + PYTHON_SQL_MODEL = "python-sql-model" + + +@app.command() +def generate( + *, + input_dir: Annotated[Path, typer.Option(help="The directory to read the JSON-schemas from.", show_default=False)], + output_dir: Annotated[Path, typer.Option(help="The directory to save the generated code to.", show_default=False)], + output_type: Annotated[GenerateType, typer.Option(help="The type of code to generate.", show_default=False)], + clear_output: Annotated[ + bool, typer.Option(help="Clear the output directory before saving the generated code.") + ] = True, +): + """ + Generate the BO4E models from the JSON-schemas in the input directory and save them in the output directory. + Several output types are available, see --output-type. + """ + pass diff --git a/src/bo4e_cli/commands/pull.py b/src/bo4e_cli/commands/pull.py new file mode 100644 index 0000000..07dbc86 --- /dev/null +++ b/src/bo4e_cli/commands/pull.py @@ -0,0 +1,43 @@ +from pathlib import Path +from typing import Annotated, Optional + +import typer + +from bo4e_cli.commands.entry import app + + +@app.command() +def pull( + *, + output_dir: Annotated[Path, typer.Option(help="The directory to save the JSON-schemas to.", show_default=False)], + version_tag: Annotated[ + str, + typer.Option( + help="The BO4E-version tag to pull the data for. " + "They will be pulled from https://github.com/bo4e/BO4E-Schemas." + ), + ] = "latest", + update_refs: Annotated[ + bool, + typer.Option( + help="Automatically update the references in the schemas. " + "Online references to BO4E-schemas will be replaced by relative paths." + ), + ] = True, + clear_output: Annotated[bool, typer.Option(help="Clear the output directory before saving the schemas.")] = True, + token: Annotated[ + Optional[str], + typer.Option( + help="A GitHub Access token to authenticate with the GitHub API. " + "Use this if you have problems with the rate limit. " + "Alternatively, you can set the environment variable GITHUB_ACCESS_TOKEN.", + envvar="GITHUB_ACCESS_TOKEN", + ), + ] = None, +): + """ + Pull all BO4E-JSON-schemas of a specific version. + Beside the json-files a .version file will be created in utf-8 format at root of the output directory. + This file is needed for other commands. + """ + pass