mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Apply some suggestions
This commit is contained in:
parent
2d5891f2e6
commit
5fc6c59ea5
1 changed files with 8 additions and 9 deletions
|
@ -166,8 +166,7 @@ class BlueprintApp:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def cmd_format(self, opts):
|
def cmd_format(self, opts):
|
||||||
to_be_reformatted = 0
|
formatted_files = 0
|
||||||
reformatted = 0
|
|
||||||
for file in opts.inputs:
|
for file in opts.inputs:
|
||||||
data = file.read()
|
data = file.read()
|
||||||
try:
|
try:
|
||||||
|
@ -179,27 +178,27 @@ class BlueprintApp:
|
||||||
formatted = decompiler.decompile_string(xml)
|
formatted = decompiler.decompile_string(xml)
|
||||||
|
|
||||||
if data != formatted:
|
if data != formatted:
|
||||||
if opts.check:
|
if not opts.check:
|
||||||
to_be_reformatted += 1
|
|
||||||
else:
|
|
||||||
open(file.name, "w").write(
|
open(file.name, "w").write(
|
||||||
formatted
|
formatted
|
||||||
) # This is very unelegant, should actually be `file.write(formatted)`
|
) # This is very unelegant, should actually be `file.write(formatted)`
|
||||||
reformatted += 1
|
|
||||||
|
formatted_files += 1
|
||||||
|
|
||||||
except PrintableError as e:
|
except PrintableError as e:
|
||||||
e.pretty_print(file.name, data, stream=sys.stderr)
|
e.pretty_print(file.name, data, stream=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if to_be_reformatted == 0 and reformatted == 0:
|
if formatted_files == 0:
|
||||||
print(f"{Colors.GREEN}{Colors.BOLD}Nothing to do.{Colors.CLEAR}")
|
print(f"{Colors.GREEN}{Colors.BOLD}Nothing to do.{Colors.CLEAR}")
|
||||||
elif opts.check:
|
elif opts.check:
|
||||||
print(
|
print(
|
||||||
f"{Colors.RED}{Colors.BOLD}{to_be_reformatted} files would be reformatted.{Colors.CLEAR}"
|
f"{Colors.RED}{Colors.BOLD}{formatted_files} files would be reformatted.{Colors.CLEAR}"
|
||||||
)
|
)
|
||||||
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
f"{Colors.RED}{Colors.BOLD}Reformatted {reformatted} file.{Colors.CLEAR}"
|
f"{Colors.RED}{Colors.BOLD}Reformatted {formatted_files} files.{Colors.CLEAR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def cmd_lsp(self, opts):
|
def cmd_lsp(self, opts):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue