Skip to content

Commit adb1d3a

Browse files
feat: Add machine-readable digest of comparison (#28)
1 parent 11df41f commit adb1d3a

File tree

20 files changed

+1051
-641
lines changed

20 files changed

+1051
-641
lines changed

diffly/cli.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ def main(
110110
)
111111
),
112112
] = False,
113+
output_json: Annotated[
114+
bool,
115+
typer.Option(
116+
"--json",
117+
help=(
118+
"Output a machine-readable JSON digest instead of a rich-formatted "
119+
"summary."
120+
),
121+
),
122+
] = False,
113123
hidden_columns: Annotated[
114124
list[str],
115125
typer.Option(
@@ -130,18 +140,20 @@ def main(
130140
rel_tol=rel_tol,
131141
abs_tol_temporal=dt.timedelta(seconds=abs_tol_temporal),
132142
)
133-
typer.echo(
134-
comparison.summary(
135-
show_perfect_column_matches=show_perfect_column_matches,
136-
top_k_column_changes=top_k_column_changes,
137-
sample_k_rows_only=sample_k_rows_only,
138-
show_sample_primary_key_per_change=show_sample_primary_key_per_change,
139-
left_name=left_name,
140-
right_name=right_name,
141-
slim=slim,
142-
hidden_columns=hidden_columns,
143-
).format(pretty=True)
143+
summary = comparison.summary(
144+
show_perfect_column_matches=show_perfect_column_matches,
145+
top_k_column_changes=top_k_column_changes,
146+
sample_k_rows_only=sample_k_rows_only,
147+
show_sample_primary_key_per_change=show_sample_primary_key_per_change,
148+
left_name=left_name,
149+
right_name=right_name,
150+
slim=slim,
151+
hidden_columns=hidden_columns,
144152
)
153+
if output_json:
154+
typer.echo(summary.to_json())
155+
else:
156+
typer.echo(summary.format(pretty=True))
145157

146158

147159
if __name__ == "__main__": # pragma: no cover

0 commit comments

Comments
 (0)