Skip to content

Commit

Permalink
[Resolve Sceptre#1498] Tweak diff output
Browse files Browse the repository at this point in the history
In order to produce output that does not confuse syntax highlighters
that recognise diff-formatted output, it is decided here to replace the
"-" character (which would often cause a diff highlighter to colour the
line as red) instead with "~" which would tend to be ignored by diff
highlighters.
  • Loading branch information
alex-harvey-z3q committed Aug 20, 2024
1 parent a8c144b commit bb51cb1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions sceptre/cli/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ def output_buffer_with_normalized_bar_lengths(
max_length = len(max(buffer, key=len))
buffer.seek(0)
full_length_star_bar = "*" * max_length
full_length_line_bar = "-" * max_length
full_length_tilde_bar = "~" * max_length
for line in buffer:
if DiffWriter.STAR_BAR in line:
line = line.replace(DiffWriter.STAR_BAR, full_length_star_bar)
if DiffWriter.LINE_BAR in line:
line = line.replace(DiffWriter.LINE_BAR, full_length_line_bar)
if DiffWriter.TILDE_BAR in line:
line = line.replace(DiffWriter.TILDE_BAR, full_length_tilde_bar)
output_stream.write(line)


Expand Down
12 changes: 6 additions & 6 deletions sceptre/diffing/diff_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DiffWriter(Generic[DiffType]):
"""

STAR_BAR = "*" * 80
LINE_BAR = "-" * 80
TILDE_BAR = "~" * 80

def __init__(
self, stack_diff: StackDiff, output_stream: TextIO, output_format: str
Expand Down Expand Up @@ -59,26 +59,26 @@ def write(self):
self._output(f"No difference to deployed stack {self.stack_name}")
return

self._output(f"--> Difference detected for stack {self.stack_name}!")
self._output(f"==> Difference detected for stack {self.stack_name}!")

if not self.is_deployed:
self._write_new_stack_details()
return

self._output(self.LINE_BAR)
self._output(self.TILDE_BAR)
self._write_config_difference()
self._output(self.LINE_BAR)
self._output(self.TILDE_BAR)
self._write_template_difference()

def _write_new_stack_details(self):
stack_config_text = self._dump_stack_config(self.stack_diff.generated_config)
self._output(
"This stack is not deployed yet!",
self.LINE_BAR,
self.TILDE_BAR,
"New Config:",
"",
stack_config_text,
self.LINE_BAR,
self.TILDE_BAR,
"New Template:",
"",
self.stack_diff.generated_template,
Expand Down
18 changes: 9 additions & 9 deletions tests/test_diffing/test_diff_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setup_method(self, method):
self.output_stream = StringIO()

self.diff_detected_message = (
f"--> Difference detected for stack {self.stack_name}!"
f"==> Difference detected for stack {self.stack_name}!"
)

@property
Expand Down Expand Up @@ -133,11 +133,11 @@ def test_write__new_stack__writes_new_stack_config_and_template(
DiffWriter.STAR_BAR,
self.diff_detected_message,
"This stack is not deployed yet!",
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
"New Config:",
"",
config_serializer(dict(self.generated_config._asdict())),
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
"New Template:",
"",
self.generated_template,
Expand All @@ -152,11 +152,11 @@ def test_write__only_config_is_different__writes_config_difference(self):
self.assert_expected_output(
DiffWriter.STAR_BAR,
self.diff_detected_message,
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
f"Config difference for {self.stack_name}:",
"",
self.diff_output,
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
"No template difference",
)

Expand All @@ -169,9 +169,9 @@ def test_write__only_template_is_different__writes_template_difference(self):
self.assert_expected_output(
DiffWriter.STAR_BAR,
self.diff_detected_message,
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
"No stack config difference",
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
f"Template difference for {self.stack_name}:",
"",
self.diff_output,
Expand All @@ -186,11 +186,11 @@ def test_write__config_and_template_are_different__writes_both_differences(self)
self.assert_expected_output(
DiffWriter.STAR_BAR,
self.diff_detected_message,
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
f"Config difference for {self.stack_name}:",
"",
self.diff_output,
DiffWriter.LINE_BAR,
DiffWriter.TILDE_BAR,
f"Template difference for {self.stack_name}:",
"",
self.diff_output,
Expand Down

0 comments on commit bb51cb1

Please sign in to comment.