@@ -218,28 +218,42 @@ async def cli(ctx: click.Context, url: str, key: str, raw: bool) -> None:
218
218
@click .option ("--active" , type = bool )
219
219
@click .option ("--dry-run" , type = bool )
220
220
@click .option ("--page-size" , type = int )
221
+ @click .option ("--running" , type = bool )
222
+ @click .option ("--type" , "-T" , type = str )
221
223
async def list_ (ctx : click .Context , / , ** filters : Any ) -> None :
222
224
"""List dispatches.
223
225
224
226
Lists all dispatches for MICROGRID_ID that match the given filters.
225
227
226
228
The target option can be given multiple times.
227
229
"""
230
+ filter_running : bool = filters .pop ("running" , False )
231
+ filter_type : str | None = filters .pop ("type" , None )
232
+
228
233
if "target" in filters :
229
234
target = filters .pop ("target" )
230
235
# Name of the parameter in client.list()
231
236
filters ["target_components" ] = target
232
237
233
238
num_dispatches = 0
239
+ num_filtered = 0
234
240
async for page in ctx .obj ["client" ].list (** filters ):
235
241
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
+
236
250
if ctx .obj ["raw" ]:
237
251
click .echo (pformat (dispatch , compact = True ))
238
252
else :
239
253
print_dispatch (dispatch )
240
254
num_dispatches += 1
241
255
242
- click .echo (f"{ num_dispatches } dispatches total ." )
256
+ click .echo (f"{ num_dispatches } dispatches, { num_filtered } filtered out ." )
243
257
244
258
245
259
@cli .command ("stream" )
0 commit comments