Skip to content

Commit

Permalink
fix(rtcl): handle missing args directly in config validator, effectiv…
Browse files Browse the repository at this point in the history
…ely in parser
  • Loading branch information
fkglr authored and rumpelsepp committed Jan 21, 2025
1 parent b87524e commit ec098cb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/gallia/commands/primitive/uds/rtcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import asyncio
import sys
from typing import Self

from pydantic import model_validator

from gallia.command import UDSScanner
from gallia.command.config import AutoInt, Field, HexBytes
Expand Down Expand Up @@ -63,6 +66,13 @@ class RTCLPrimitiveConfig(UDSScannerConfig):
metavar="SECONDS",
)

@model_validator(mode="after")
def check_action(self) -> Self:
if not any((self.start, self.stop, self.results)):
raise ValueError("No instructions were given (start/stop/results)")

return self


class RTCLPrimitive(UDSScanner):
"""Start or stop a provided routine or request its results"""
Expand All @@ -81,13 +91,6 @@ async def main(self) -> None:
logger.critical(f"Could not change to session: {g_repr(self.config.session)}: {e!r}")
sys.exit(1)

if (
self.config.start is False
and self.config.stop is False
and (self.config.results is False)
):
logger.warning("No instructions were given (start/stop/results)")

if self.config.start:
resp: (
NegativeResponse | RoutineControlResponse
Expand Down

0 comments on commit ec098cb

Please sign in to comment.