Skip to content

Commit 292aa98

Browse files
Format CLI output for pydantic classes
1 parent b516d02 commit 292aa98

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ads/cli.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
2+
import json
33

4-
# Copyright (c) 2021, 2024 Oracle and/or its affiliates.
4+
# Copyright (c) 2021, 2025 Oracle and/or its affiliates.
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6-
76
import sys
87
import traceback
9-
from dataclasses import is_dataclass
108

119
import fire
10+
from pydantic import BaseModel
1211

1312
from ads.common import logger
1413

@@ -84,7 +83,14 @@ def serialize(data):
8483
The string representation of each dataclass object.
8584
"""
8685
if isinstance(data, list):
86+
for item in data:
87+
if isinstance(item, BaseModel):
88+
print(json.dumps(item.dict(), indent=4))
89+
else:
90+
print(str(item))
8791
[print(str(item)) for item in data]
92+
elif isinstance(data, BaseModel):
93+
print(json.dumps(data.dict(), indent=4))
8894
else:
8995
print(str(data))
9096

0 commit comments

Comments
 (0)