@@ -179,6 +179,7 @@ def filter_manifest(manifest: Manifest, global_config: Namespace) -> Manifest |
179179 logger .error ("Error while collecting sessions." )
180180 logger .error (exc .args [0 ])
181181 return 3
182+
182183 if not manifest and not global_config .list_sessions :
183184 print ("No sessions selected. Please select a session with -s <session name>.\n " )
184185 _produce_listing (manifest , global_config )
@@ -264,6 +265,23 @@ def _produce_listing(manifest: Manifest, global_config: Namespace) -> None:
264265 )
265266
266267
268+ def _produce_json_listing (manifest : Manifest , global_config : Namespace ) -> None :
269+ report = []
270+ for session , selected in manifest .list_all_sessions ():
271+ if selected :
272+ report .append (
273+ {
274+ "session" : session .friendly_name ,
275+ "name" : session .name ,
276+ "description" : session .description or "" ,
277+ "python" : session .func .python ,
278+ "tags" : session .tags ,
279+ "call_spec" : getattr (session .func , "call_spec" , {}),
280+ }
281+ )
282+ print (json .dumps (report ))
283+
284+
267285def honor_list_request (manifest : Manifest , global_config : Namespace ) -> Manifest | int :
268286 """If --list was passed, simply list the manifest and exit cleanly.
269287
@@ -275,10 +293,18 @@ def honor_list_request(manifest: Manifest, global_config: Namespace) -> Manifest
275293 Union[~.Manifest,int]: ``0`` if a listing is all that is requested,
276294 the manifest otherwise (to be sent to the next task).
277295 """
278- if not global_config .list_sessions :
296+ if not ( global_config .list_sessions or global_config . json ) :
279297 return manifest
280298
281- _produce_listing (manifest , global_config )
299+ # JSON output requires list sessions also be specified
300+ if global_config .json and not global_config .list_sessions :
301+ logger .error ("Must specify --list-sessions with --json" )
302+ return 3
303+
304+ if global_config .json :
305+ _produce_json_listing (manifest , global_config )
306+ else :
307+ _produce_listing (manifest , global_config )
282308
283309 return 0
284310
0 commit comments