File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 88import sys
99
1010import fire
11+ from dataclasses import is_dataclass
1112from ads .common import logger
1213
1314try :
@@ -70,11 +71,28 @@ def _SeparateFlagArgs(args):
7071fire .core .parser .SeparateFlagArgs = _SeparateFlagArgs
7172
7273
74+ def serialize (data ):
75+ """Serialize dataclass objects or lists of dataclass objects.
76+ Parameters:
77+ data: A dataclass object or a list of dataclass objects.
78+ Returns:
79+ None
80+ Prints:
81+ The string representation of each dataclass object.
82+ """
83+ if isinstance (data , list ):
84+ [print (str (item )) for item in data ]
85+ else :
86+ print (str (data ))
87+
88+
7389def cli ():
7490 if len (sys .argv ) > 1 and sys .argv [1 ] == "aqua" :
7591 from ads .aqua .cli import AquaCommand
7692
77- fire .Fire (AquaCommand , command = sys .argv [2 :], name = "ads aqua" )
93+ fire .Fire (
94+ AquaCommand , command = sys .argv [2 :], name = "ads aqua" , serialize = serialize
95+ )
7896 else :
7997 click_cli ()
8098
Original file line number Diff line number Diff line change @@ -195,7 +195,10 @@ def to_json(
195195 `None` in case when `uri` provided.
196196 """
197197 json_string = json .dumps (
198- self .to_dict (** kwargs ), cls = encoder , default = default or self .serialize
198+ self .to_dict (** kwargs ),
199+ cls = encoder ,
200+ default = default or self .serialize ,
201+ indent = 4 ,
199202 )
200203 if uri :
201204 self ._write_to_file (s = json_string , uri = uri , ** kwargs )
@@ -463,9 +466,7 @@ def from_dict(
463466 "These fields will be ignored."
464467 )
465468
466- obj = cls (
467- ** {key : obj_dict .get (key ) for key in allowed_fields }
468- )
469+ obj = cls (** {key : obj_dict .get (key ) for key in allowed_fields })
469470
470471 for key , value in obj_dict .items ():
471472 if (
You can’t perform that action at this time.
0 commit comments