Skip to content

Commit

Permalink
Fix reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
benber86 committed Dec 30, 2024
1 parent 853c979 commit 7b6d49e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 11 additions & 8 deletions src/mamushi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class ProcessResult:
changed: Changed | None = None
error_message: str | None = None
traceback_str: str | None = None
formatted_content: str | None = None


def format_stdin_to_stdout(src: str, dst: str):
def format_stdin_to_stdout(src: str, dst: str, file_path: Path | None):
"""Format file on stdin. Return True if changed.
If content is None, it's read from sys.stdin.
Expand All @@ -46,8 +47,8 @@ def format_stdin_to_stdout(src: str, dst: str):
write_through=True,
)
now = datetime.utcnow()
src_name = f"STDIN\t{then} +0000"
dst_name = f"STDOUT\t{now} +0000"
src_name = f"STDIN\t{then} +0000 - {file_path}"
dst_name = f"STDOUT\t{now} +0000 - {file_path}"
d = diff(src, dst, src_name, dst_name)
d = color_diff(d)
f.write(d)
Expand Down Expand Up @@ -103,16 +104,16 @@ def reformat(
return ProcessResult(src=src, success=True, changed=changed)

if diff:
format_stdin_to_stdout(contract, res)
format_stdin_to_stdout(contract, res, src)
return ProcessResult(src=src, success=True, changed=changed)

if in_place:
with open(src, "w") as fp:
fp.write(res)
else:
print(res)

return ProcessResult(src=src, success=True, changed=changed)
return ProcessResult(
src=src, success=True, changed=changed, formatted_content=res
)


@click.command()
Expand Down Expand Up @@ -215,10 +216,12 @@ def main(
for result in results:
if not result.success:
if verbose and result.traceback_str:
print(result.traceback_str, file=sys.stderr)
out(result.traceback_str)
report.failed(result.src, result.error_message)
else:
report.done(result.src, result.changed)
if not in_place and result.formatted_content:
click.echo(result.formatted_content)

error_msg = "Oh no! 💥 💔 💥"
if verbose or not quiet:
Expand Down
4 changes: 0 additions & 4 deletions tests/test_mamushi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def test_diff_file(runner):
assert result.exit_code == 0
assert "would reformat" in result.stderr
assert "would be reformatted" in result.stderr
assert "\033[1m" in result.stdout
assert "\033[36m" in result.stdout
assert "\033[32m" in result.stdout
assert "\033[31m" in result.stdout

finally:
os.unlink(tmp_file)
Expand Down

0 comments on commit 7b6d49e

Please sign in to comment.