Skip to content

Commit

Permalink
tidy CLI for schema output and order help
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 21, 2023
1 parent ad6b92e commit 6d51b91
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 131 deletions.
3 changes: 2 additions & 1 deletion src/ibek/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from ibek.support_cmds.commands import support_cli

from ._version import __version__
from .globals import NaturalOrderGroup

cli = typer.Typer()
cli = typer.Typer(cls=NaturalOrderGroup)


cli.add_typer(
Expand Down
6 changes: 6 additions & 0 deletions src/ibek/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from jinja2 import Template
from pydantic import BaseModel, ConfigDict
from typer.core import TyperGroup

from .utils import UTILS

Expand Down Expand Up @@ -45,6 +46,11 @@ class BaseSettings(BaseModel):
)


class NaturalOrderGroup(TyperGroup):
def list_commands(self, ctx):
return self.commands.keys()


def render_with_utils(context: Dict, template_text: str) -> str:
"""
Render a Jinja template with the global __utils__ object in the context
Expand Down
50 changes: 28 additions & 22 deletions src/ibek/ioc_cmds/commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import subprocess
from pathlib import Path
from typing import Annotated, List
from typing import Annotated, List, Optional

import typer
from jinja2 import Template
Expand All @@ -14,26 +14,11 @@
MAKE_FOLDER,
MODULES,
PROJECT_ROOT_FOLDER,
NaturalOrderGroup,
)
from ibek.ioc_cmds.docker import build_dockerfile

ioc_cli = typer.Typer()


@ioc_cli.command()
def generate_schema(
definitions: List[Path] = typer.Argument(
..., help="The filepath to a support module definition file"
),
output: Path = typer.Argument(..., help="The filename to write the schema to"),
):
"""
Create a json schema from a <support_module>.ibek.support.yaml file
"""

ioc_model = ioc_create_model(definitions)
schema = json.dumps(ioc_model.model_json_schema(), indent=2)
output.write_text(schema)
ioc_cli = typer.Typer(cls=NaturalOrderGroup)


@ioc_cli.command()
Expand Down Expand Up @@ -89,12 +74,33 @@ def build(
/ "Dockerfile",
):
"""
Attempt to interpret the Dockerfile and run the commands inside the
developer container.
EXPERIMENTAL: Attempt to interpret the Dockerfile and run it's commands
inside the devcontainer. For internal, incremental builds of the Dockerfile.
Useful for debugging the Dockerfile without having to build the whole
container from outside of the IOC devcontainer.
EXPERIMENTAL FEATURE
"""
build_dockerfile(dockerfile, start, stop)


@ioc_cli.command()
def generate_schema(
definitions: List[Path] = typer.Argument(
..., help="File paths to one or more support module YAML files"
),
output: Annotated[
Optional[Path],
typer.Option(help="The file path to the schema file to be written"),
] = None,
):
"""
Create a json schema from a number of support_module.ibek.support.yaml
files
"""

ioc_model = ioc_create_model(definitions)
schema = json.dumps(ioc_model.model_json_schema(), indent=2)
if output is None:
print(schema)
else:
output.write_text(schema)
3 changes: 2 additions & 1 deletion src/ibek/startup_cmds/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
create_db_script,
ioc_deserialize,
)
from ibek.globals import NaturalOrderGroup

startup_cli = typer.Typer()
startup_cli = typer.Typer(cls=NaturalOrderGroup)


@startup_cli.command()
Expand Down
Loading

0 comments on commit 6d51b91

Please sign in to comment.