diff --git a/diracx-cli/pyproject.toml b/diracx-cli/pyproject.toml index b103e0ca..431d0a01 100644 --- a/diracx-cli/pyproject.toml +++ b/diracx-cli/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "gitpython", "pydantic", "rich", - "typer <0.12.4", + "typer", "pyyaml", ] dynamic = ["version"] diff --git a/diracx-cli/src/diracx/cli/jobs.py b/diracx-cli/src/diracx/cli/jobs.py index ceeed695..e4430b88 100644 --- a/diracx-cli/src/diracx/cli/jobs.py +++ b/diracx-cli/src/diracx/cli/jobs.py @@ -20,6 +20,12 @@ app = AsyncTyper() +available_operators = ( + f"Scalar operators: {', '.join([op.value for op in ScalarSearchOperator])}. " + f"Vector operators: {', '.join([op.value for op in VectorSearchOperator])}." +) + + def parse_condition(value: str) -> SearchSpec: parameter, operator, rest = value.split(" ", 2) if operator in set(ScalarSearchOperator): @@ -51,15 +57,18 @@ async def search( "Owner", "LastUpdateTime", ], - condition: Annotated[list[SearchSpec], Option(parser=parse_condition)] = [], + condition: Annotated[ + list[str], Option(help=f'Example: "JobID eq 1000". {available_operators}') + ] = [], all: bool = False, page: int = 1, per_page: int = 10, ): + search_specs = [parse_condition(cond) for cond in condition] async with DiracClient() as api: jobs, content_range = await api.jobs.search( parameters=None if all else parameter, - search=condition if condition else None, + search=search_specs if search_specs else None, page=page, per_page=per_page, cls=lambda _, jobs, headers: ( diff --git a/diracx-cli/tests/test_jobs.py b/diracx-cli/tests/test_jobs.py index 9ae2a66d..a0992b9a 100644 --- a/diracx-cli/tests/test_jobs.py +++ b/diracx-cli/tests/test_jobs.py @@ -8,7 +8,6 @@ from pytest import raises from diracx import cli -from diracx.core.models import ScalarSearchSpec from diracx.core.preferences import get_diracx_preferences TEST_JDL = """ @@ -80,8 +79,7 @@ async def test_search(with_cli_login, jdl_file, capfd): assert "JobGroup" in cap.out # Search for a job that doesn't exist - condition = ScalarSearchSpec(parameter="Status", operator="eq", value="nonexistent") - await cli.jobs.search(condition=[condition]) + await cli.jobs.search(condition=["Status eq nonexistent"]) cap = capfd.readouterr() assert cap.err == "" assert "[]" == cap.out.strip() @@ -114,7 +112,7 @@ async def test_search(with_cli_login, jdl_file, capfd): assert "Showing all jobs" in cap.out # Search for a job that doesn't exist - await cli.jobs.search(condition=[condition]) + await cli.jobs.search(condition=["Status eq nonexistent"]) cap = capfd.readouterr() assert cap.err == "" assert "No jobs found" in cap.out