mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Formatter CLI: Provide option to suppress diff
This commit is contained in:
parent
1c8d7daea2
commit
84e529a4a8
1 changed files with 24 additions and 15 deletions
|
@ -90,6 +90,13 @@ class BlueprintApp:
|
||||||
default=2,
|
default=2,
|
||||||
type=int,
|
type=int,
|
||||||
)
|
)
|
||||||
|
format.add_argument(
|
||||||
|
"-n",
|
||||||
|
"--no-diff",
|
||||||
|
help="Do not print a full diff of the changes",
|
||||||
|
default=False,
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
format.add_argument(
|
format.add_argument(
|
||||||
"inputs",
|
"inputs",
|
||||||
nargs="+",
|
nargs="+",
|
||||||
|
@ -221,23 +228,25 @@ class BlueprintApp:
|
||||||
file.write(formatted_str)
|
file.write(formatted_str)
|
||||||
happened = "Formatted"
|
happened = "Formatted"
|
||||||
|
|
||||||
diff_lines = []
|
if not opts.no_diff:
|
||||||
a_lines = data.splitlines(keepends=True)
|
diff_lines = []
|
||||||
b_lines = formatted_str.splitlines(keepends=True)
|
a_lines = data.splitlines(keepends=True)
|
||||||
|
b_lines = formatted_str.splitlines(keepends=True)
|
||||||
|
|
||||||
for line in difflib.unified_diff(
|
for line in difflib.unified_diff(
|
||||||
a_lines, b_lines, fromfile=file.name, tofile=file.name, n=5
|
a_lines, b_lines, fromfile=file.name, tofile=file.name, n=5
|
||||||
):
|
):
|
||||||
# Work around https://bugs.python.org/issue2142
|
# Work around https://bugs.python.org/issue2142
|
||||||
# See:
|
# See:
|
||||||
# https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html
|
# https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html
|
||||||
if line[-1] == "\n":
|
if line[-1] == "\n":
|
||||||
diff_lines.append(line)
|
diff_lines.append(line)
|
||||||
else:
|
else:
|
||||||
diff_lines.append(line + "\n")
|
diff_lines.append(line + "\n")
|
||||||
diff_lines.append("\\ No newline at end of file\n")
|
diff_lines.append("\\ No newline at end of file\n")
|
||||||
|
|
||||||
|
print("".join(diff_lines))
|
||||||
|
|
||||||
print("".join(diff_lines))
|
|
||||||
to_print = Colors.BOLD
|
to_print = Colors.BOLD
|
||||||
if errored:
|
if errored:
|
||||||
to_print += f"{Colors.RED}Skipped {file.name}: Will not overwrite file with compile errors"
|
to_print += f"{Colors.RED}Skipped {file.name}: Will not overwrite file with compile errors"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue