chore: better cli options name

This commit is contained in:
Benjamin Labrecque
2026-07-28 16:33:32 +02:00
parent 63e6641698
commit 4379846881
3 changed files with 16 additions and 16 deletions
+7 -7
View File
@@ -8,14 +8,14 @@ from models import ServiceRegistry
class GuiConfig(BaseModel):
gui_option: GuiOption
option: GuiOption
raw_ui_filename: Optional[str] = None
def should_create_new_ui(self):
return self.gui_option == GuiOption.NEW
return self.option == GuiOption.NEW
def should_use_existing_ui(self):
return self.gui_option == GuiOption.EXISTING
return self.option == GuiOption.EXISTING
@property
def ui_filename(self) -> str:
@@ -25,10 +25,10 @@ class GuiConfig(BaseModel):
return self.raw_ui_filename
def assert_valid(self, service_registry: ServiceRegistry):
if self.gui_option == GuiOption.EXISTING:
if self.option == GuiOption.EXISTING:
if self.raw_ui_filename is None:
raise InvalidCliOptions(
f"Must specify --ui-filename when --gui-option is {GuiOption.EXISTING}"
f"Must specify --gui-existing-service-name when --gui-option is {GuiOption.EXISTING}"
)
try:
service_registry.assert_service_exists(self.ui_filename)
@@ -37,7 +37,7 @@ class GuiConfig(BaseModel):
f"Could not find service with name {self.ui_filename} in service_registry."
) from e
if self.gui_option == GuiOption.NONE and self.raw_ui_filename:
if self.option == GuiOption.NONE and self.raw_ui_filename:
raise InvalidCliOptions(
f"Cannot specify --ui-filename when --gui-option is {GuiOption.NONE}"
f"Cannot specify --gui-existing-service-name when --gui-option is {GuiOption.NONE}"
)
+6 -6
View File
@@ -47,17 +47,17 @@ def add(
help="By default, a new GUI is created. You can specificy if a GUI already exists, "
"and this service should use that GUI, or if no GUI is needed for this service",
),
ui_filename: str | None = typer.Option(
raw_ui_filename: str | None = typer.Option(
None,
"--ui-filename",
"-f",
help="If '--gui=existing', specify the name of the service (in CamelCase) whose UI this service should use",
"--gui-existing-service-name",
"-s",
help="If '--gui=existing', specify the name of an existing service (in CamelCase) whose GUI this new service should use",
),
):
init_logging()
if gui_option == GuiOption.NEW:
ui_filename = name
gui_config = GuiConfig(gui_option=gui_option, raw_ui_filename=ui_filename)
raw_ui_filename = name
gui_config = GuiConfig(option=gui_option, raw_ui_filename=raw_ui_filename)
ctx = ServicesContext.load_from_disk(Paths())
service_creator = ServiceCreator(ctx=ctx, repo_manager=GitRepoManager(REPO_ROOT))
+3 -3
View File
@@ -71,7 +71,7 @@ def test_add_new_service(tmp_path, mocker: MockerFixture):
ctx._write_paths = write_paths
service_name = "TestService99-X00"
gui_config = GuiConfig(gui_option=GuiOption.NEW, raw_ui_filename=service_name)
gui_config = GuiConfig(option=GuiOption.NEW, raw_ui_filename=service_name)
creator = ServiceCreator(ctx=ctx, repo_manager=mocker.Mock(spec=GitRepoManager))
creator.add_service(
name=service_name,
@@ -98,7 +98,7 @@ def test_raise_if_gui_options_invalid(gui_option, raw_ui_filename, mocker):
paths = Paths(repo_root=TEST_REPO_ROOT)
ctx = ServicesContext.load_from_disk(paths)
gui_config = GuiConfig(gui_option=gui_option, raw_ui_filename=raw_ui_filename)
gui_config = GuiConfig(option=gui_option, raw_ui_filename=raw_ui_filename)
creator = ServiceCreator(ctx=ctx, repo_manager=mocker.Mock(spec=GitRepoManager))
with pytest.raises(InvalidCliOptions):
creator.add_service(
@@ -119,7 +119,7 @@ def test_existing_gui_ok(gui_option, raw_ui_filename):
paths = Paths(repo_root=TEST_REPO_ROOT)
ctx = ServicesContext.load_from_disk(paths)
gui_config = GuiConfig(gui_option=gui_option, raw_ui_filename=raw_ui_filename)
gui_config = GuiConfig(option=gui_option, raw_ui_filename=raw_ui_filename)
gui_config.assert_valid(service_registry=ctx.service_registry)