Skip to content

Commit c9ffade

Browse files
committed
Add two new filters to the dispatch list command
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 56d9abc commit c9ffade

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
* `dispatch-cli` supports now the parameter `--type` and `--running` to filter the list of running services by type and status, respectively.
1414

1515
## Bug Fixes
1616

src/frequenz/client/dispatch/__main__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,28 +218,42 @@ async def cli(ctx: click.Context, url: str, key: str, raw: bool) -> None:
218218
@click.option("--active", type=bool)
219219
@click.option("--dry-run", type=bool)
220220
@click.option("--page-size", type=int)
221+
@click.option("--running", type=bool)
222+
@click.option("--type", "-T", type=str)
221223
async def list_(ctx: click.Context, /, **filters: Any) -> None:
222224
"""List dispatches.
223225
224226
Lists all dispatches for MICROGRID_ID that match the given filters.
225227
226228
The target option can be given multiple times.
227229
"""
230+
filter_running: bool = filters.pop("running", False)
231+
filter_type: str | None = filters.pop("type", None)
232+
228233
if "target" in filters:
229234
target = filters.pop("target")
230235
# Name of the parameter in client.list()
231236
filters["target_components"] = target
232237

233238
num_dispatches = 0
239+
num_filtered = 0
234240
async for page in ctx.obj["client"].list(**filters):
235241
for dispatch in page:
242+
if filter_running and not dispatch.started:
243+
num_filtered += 1
244+
continue
245+
246+
if filter_type and dispatch.type != filter_type:
247+
num_filtered += 1
248+
continue
249+
236250
if ctx.obj["raw"]:
237251
click.echo(pformat(dispatch, compact=True))
238252
else:
239253
print_dispatch(dispatch)
240254
num_dispatches += 1
241255

242-
click.echo(f"{num_dispatches} dispatches total.")
256+
click.echo(f"{num_dispatches} dispatches, {num_filtered} filtered out.")
243257

244258

245259
@cli.command("stream")

0 commit comments

Comments
 (0)