Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lord-haffi committed Aug 19, 2024
1 parent 9c3643d commit 3dd79a9
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 4 additions & 0 deletions src/bo4e_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from bo4e_cli.commands.entry import app

if __name__ == "__main__":
app()
7 changes: 7 additions & 0 deletions src/bo4e_cli/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
21 changes: 21 additions & 0 deletions src/bo4e_cli/commands/diff.py
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions src/bo4e_cli/commands/edit.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/bo4e_cli/commands/entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import typer

app = typer.Typer()
34 changes: 34 additions & 0 deletions src/bo4e_cli/commands/generate.py
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions src/bo4e_cli/commands/pull.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3dd79a9

Please sign in to comment.