Skip to content

Commit 9c641d2

Browse files
authored
Add print_diff_to_console flag (#81)
1 parent 4d9cd86 commit 9c641d2

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/rpdk/guard_rail/core/data_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Stateful:
5252
current_schema: Dict[str, Any]
5353
previous_schema: Dict[str, Any]
5454
rules: List[str] = field(default_factory=list)
55+
print_diff_to_console: bool = field(default=True)
5556

5657

5758
@dataclass(unsafe_hash=True)

src/rpdk/guard_rail/core/runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def __execute__(schema_exec, ruleset):
184184
return output
185185

186186
schema_difference = schema_diff(
187-
previous_json=payload.previous_schema, current_json=payload.current_schema
187+
previous_json=payload.previous_schema,
188+
current_json=payload.current_schema,
189+
print_diff_to_console=payload.print_diff_to_console,
188190
)
189191

190192
schema_to_execute = __exec_rules__(schema=schema_difference)

src/rpdk/guard_rail/core/stateful.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ class DIFFKEYS:
9393
}
9494

9595

96-
def schema_diff(previous_json: Dict[str, Any], current_json: Dict[str, Any]):
96+
def schema_diff(
97+
previous_json: Dict[str, Any],
98+
current_json: Dict[str, Any],
99+
print_diff_to_console: bool = True,
100+
):
97101
"""schema diff function to get formatted schema diff from deep diff"""
98102

99103
previous_schema = resolve_schema(previous_json)
@@ -107,14 +111,15 @@ def schema_diff(previous_json: Dict[str, Any], current_json: Dict[str, Any]):
107111
)
108112

109113
meta_diff = _translate_meta_diff(deep_diff.to_dict())
110-
console.rule("[bold red][GENERATED DIFF BETWEEN SCHEMAS]")
111-
console.print(
112-
meta_diff,
113-
style="link https://google.com",
114-
highlight=True,
115-
justify="left",
116-
soft_wrap=True,
117-
)
114+
if print_diff_to_console:
115+
console.rule("[bold red][GENERATED DIFF BETWEEN SCHEMAS]")
116+
console.print(
117+
meta_diff,
118+
style="link https://google.com",
119+
highlight=True,
120+
justify="left",
121+
soft_wrap=True,
122+
)
118123
return meta_diff
119124

120125

0 commit comments

Comments
 (0)