@@ -129,11 +129,17 @@ def execute_task(log: bool, run_id: str, params: str, **extra: Any) -> None:
129129
130130
131131@click .command ()
132+ @click .option (
133+ "--tags" ,
134+ "-t" ,
135+ multiple = True ,
136+ help = "Only list tasks that have at least one of these tags" ,
137+ )
132138@click .pass_context
133- def ls (ctx : click .Context ) -> None :
139+ def ls (ctx : click .Context , tags : tuple [ str , ...] ) -> None :
134140 """List all tasks with their schedules"""
135141 task_manager = ctx_task_manager (ctx )
136- table = asyncio .run (tasks_table (task_manager ))
142+ table = asyncio .run (tasks_table (task_manager , tags = set ( tags ) ))
137143 console = Console ()
138144 console .print (table )
139145
@@ -219,7 +225,7 @@ async def enable_task(task_manager: TaskManager, task: str, enable: bool) -> Non
219225 raise click .ClickException (f"Task { task } not found" ) from e
220226
221227
222- async def tasks_table (task_manager : TaskManager ) -> Table :
228+ async def tasks_table (task_manager : TaskManager , tags : set [ str ] | None = None ) -> Table :
223229 task_info = await task_manager .broker .get_tasks_info ()
224230 dynamic = {t .name : t for t in task_info }
225231 table = Table (title = "Tasks" )
@@ -229,16 +235,20 @@ async def tasks_table(task_manager: TaskManager) -> Table:
229235 table .add_column ("CPU bound" , style = "magenta" )
230236 table .add_column ("Timeout secs" , style = "green" )
231237 table .add_column ("Priority" , style = "magenta" )
238+ table .add_column ("Tags" , style = "blue" )
232239 table .add_column ("Description" , style = "green" )
233240 for name in sorted (task_manager .registry ):
234241 task = task_manager .registry [name ]
242+ if tags and not tags .intersection (task .tags ):
243+ continue
235244 table .add_row (
236245 name ,
237246 ":white_check_mark:" if dynamic [name ].enabled else "[red]:x:" ,
238- str (task .schedule ),
247+ str (task .schedule ) if task . schedule is not None else "[red]:x:" ,
239248 ":white_check_mark:" if task .cpu_bound else "[red]:x:" ,
240249 str (task .timeout_seconds ),
241250 str (task .priority ),
251+ ", " .join (sorted (task .tags )),
242252 task .short_description ,
243253 )
244254 return table
0 commit comments