diff --git a/libervia/cli/constants.py b/libervia/cli/constants.py index 10f8c08d..b2708cfd 100644 --- a/libervia/cli/constants.py +++ b/libervia/cli/constants.py @@ -44,6 +44,7 @@ class Const(constants.Const): OUTPUT_LIST_XML = "list_xml" # list of XML nodes (as unicode strings) OUTPUT_XMLUI = "xmlui" # XMLUI as unicode string OUTPUT_LIST_XMLUI = "list_xmlui" # list of XMLUI (as unicode strings) + OUTPUT_MODEL = "model" # Pydantic model OUTPUT_TYPES = ( OUTPUT_CUSTOM, OUTPUT_TEXT, @@ -57,6 +58,7 @@ class Const(constants.Const): OUTPUT_LIST_XML, OUTPUT_XMLUI, OUTPUT_LIST_XMLUI, + OUTPUT_MODEL, ) OUTPUT_NAME_SIMPLE = "simple" OUTPUT_NAME_XML = "xml" @@ -81,7 +83,7 @@ class Const(constants.Const): A_SUCCESS = A.BOLD + A.FG_GREEN A_FAILURE = A.BOLD + A.FG_RED A_WARNING = A.BOLD + A.FG_RED - #  A_PROMPT_* is for shell + # A_PROMPT_* is for shell A_PROMPT_PATH = A.BOLD + A.FG_CYAN A_PROMPT_SUF = A.BOLD # Files diff --git a/libervia/cli/output_std.py b/libervia/cli/output_std.py index 6e5688ce..d580657e 100644 --- a/libervia/cli/output_std.py +++ b/libervia/cli/output_std.py @@ -130,9 +130,19 @@ class Json: host.register_output(C.OUTPUT_MESS, C.OUTPUT_NAME_JSON_RAW, self.dump) host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_JSON, self.dump_pretty) host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_JSON_RAW, self.dump) + host.register_output( + C.OUTPUT_MODEL, + C.OUTPUT_NAME_JSON, + lambda model: self.dump_pretty(model.model_dump_json()), + ) + host.register_output( + C.OUTPUT_MODEL, + C.OUTPUT_NAME_JSON_RAW, + lambda model: self.dump(model.model_dump_json()), + ) def dump(self, data): - self.host.console.print_json(data=data, indent=None, highlight=False, default=str) + self.host.console.print_json(json=data, indent=None, highlight=False, default=str) def dump_pretty(self, data): - self.host.console.print_json(data=data, indent=4, default=str) + self.host.console.print_json(json=data, indent=4, default=str)