@@ -190,6 +190,7 @@ def show(
190190 """
191191 import yaml
192192 from nested_lookup import nested_delete
193+ from rich .markdown import Markdown
193194 from rich .syntax import Syntax
194195
195196 from esmvalcore .config import CFG
@@ -203,7 +204,9 @@ def show(
203204 if filter
204205 else ""
205206 )
206- self ._console .print (f"# Current configuration{ exclude_msg } :" )
207+ self ._console .print (
208+ Markdown (f"# Current configuration{ exclude_msg } \n <br>" ),
209+ )
207210 self ._console .print (
208211 Syntax (
209212 yaml .safe_dump (cfg ),
@@ -450,28 +453,48 @@ class Recipes:
450453 https://docs.esmvaltool.org/en/latest/recipes/index.html.
451454 """
452455
453- @staticmethod
454- def list () -> None :
456+ def __init__ (self ) -> None :
457+ from rich .console import Console
458+
459+ self ._console = Console (soft_wrap = True )
460+
461+ def list (self ) -> None :
455462 """List all installed recipes.
456463
457464 Show all installed recipes, grouped by folder.
458465 """
466+ import yaml
467+ from rich .markdown import Markdown
468+
459469 from .config ._diagnostics import DIAGNOSTICS
460- from .config ._logging import configure_logging
461470
462- configure_logging (console_log_level = "info" )
463471 recipes_folder = DIAGNOSTICS .recipes
464- logger .info ("Showing recipes installed in %s" , recipes_folder )
465- print ("# Installed recipes" ) # noqa: T201
466- for recipe_root , _ , files in sorted (os .walk (recipes_folder )):
467- root = os .path .relpath (recipe_root , recipes_folder )
468- if root == "." :
469- root = ""
470- if root :
471- print (f"\n # { root .replace (os .sep , ' - ' ).title ()} " ) # noqa: T201
472+ messages = [f"# ESMValTool recipes available in `{ DIAGNOSTICS .path } `" ]
473+ for recipe_root , _ , files in sorted (recipes_folder .walk ()):
474+ subdir = recipe_root .relative_to (recipes_folder ).as_posix ()
475+ if subdir == "." :
476+ subdir = ""
477+ if subdir :
478+ messages .append (
479+ f"\n ## { subdir .replace (os .sep , ' - ' ).title ()} " ,
480+ )
472481 for filename in sorted (files ):
473- if filename .endswith (".yml" ):
474- print (os .path .join (root , filename )) # noqa: T201
482+ recipe = recipe_root / filename
483+ if recipe .suffix == ".yml" :
484+ title = (
485+ (
486+ yaml .safe_load (
487+ recipe .read_text (encoding = "utf-8" ),
488+ )
489+ or {}
490+ )
491+ .get ("documentation" , {})
492+ .get ("title" , "" )
493+ )
494+ messages .append (
495+ f"- `{ recipe .relative_to (recipes_folder )} `: { title } " ,
496+ )
497+ self ._console .print (Markdown ("\n " .join (messages )))
475498
476499 @staticmethod
477500 def get (recipe : str ) -> None :
@@ -502,8 +525,7 @@ def get(recipe: str) -> None:
502525 shutil .copy (installed_recipe , Path (recipe ).name )
503526 logger .info ("Recipe %s successfully copied" , recipe )
504527
505- @staticmethod
506- def show (recipe : str ) -> None :
528+ def show (self , recipe : str ) -> None :
507529 """Show the given recipe in console.
508530
509531 Use this command to see the contents of any installed recipe.
@@ -513,22 +535,27 @@ def show(recipe: str) -> None:
513535 recipe: str
514536 Name of the recipe to get, including any subdirectories.
515537 """
538+ from rich .markdown import Markdown
539+ from rich .syntax import Syntax
540+
516541 from .config ._diagnostics import DIAGNOSTICS
517- from .config ._logging import configure_logging
518542 from .exceptions import RecipeError
519543
520- configure_logging (console_log_level = "info" )
521544 installed_recipe = DIAGNOSTICS .recipes / recipe
522545 if not installed_recipe .exists ():
523546 msg = (
524547 f"Recipe { recipe } not found. To list all available recipes, "
525548 'execute "esmvaltool list"'
526549 )
527550 raise RecipeError (msg )
528- msg = f"Recipe { recipe } "
529- logger .info (msg )
530- logger .info ("=" * len (msg ))
531- print (installed_recipe .read_text (encoding = "utf-8" )) # noqa: T201
551+ self ._console .print (Markdown (f"# Recipe `{ recipe } `" ))
552+ self ._console .print (
553+ Syntax (
554+ installed_recipe .read_text (encoding = "utf-8" ),
555+ "yaml" ,
556+ background_color = "default" ,
557+ ),
558+ )
532559
533560
534561class ESMValTool :
0 commit comments