feat(quiet): updated output of the --quiet flag to reduce unneeded verbose stuff

This commit is contained in:
Christopher Pickering 2022-09-26 13:47:41 +02:00
parent 67e8c64762
commit b53f670af8
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
3 changed files with 19 additions and 19 deletions

View file

@ -221,7 +221,7 @@ def main(
Style.RESET_ALL + " ",
)
)
if config.stdin is False or config.lint:
if config.stdin is False and config.quiet is False:
echo()
worker_count = os.cpu_count() or 1
@ -239,7 +239,7 @@ def main(
func = partial(process, config)
futures = {exe.submit(func, this_file): this_file for this_file in file_list}
if temp_file is None or config.lint:
if temp_file is None:
elapsed = "00:00"
with tqdm(
total=len(file_list),
@ -277,6 +277,9 @@ def main(
leave=True,
)
finished_bar.close()
else:
for future in as_completed(futures):
file_errors.append(future.result())
if temp_file and (config.reformat or config.check):
# if using stdin, only give back formatted code.

View file

@ -31,7 +31,9 @@ def print_output(
lint_error_count = 0
format_error_count = 0
if config.stdin is False or config.lint:
print_blanks = config.stdin is False and config.quiet is False
if print_blanks:
echo()
for error in sorted(file_errors, key=lambda x: next(iter(list(x.values())[0]))):
@ -58,22 +60,26 @@ def print_output(
f"Linted {file_quantity}, found {lint_error_count} {error_case}."
)
if config.stdin is False or config.lint:
if print_blanks:
echo()
if config.stdin is False and (config.reformat or config.check):
if (
config.quiet is False
and config.stdin is False
and (config.reformat or config.check)
):
reformat_success_color = (
Fore.RED + Style.BRIGHT if (format_error_count) > 0 else Fore.BLUE
)
echo(f"{reformat_success_color}{reformat_success_message}{Style.RESET_ALL}")
if config.lint:
if config.lint and config.quiet is False:
lint_success_color = (
Fore.RED + Style.BRIGHT if (lint_error_count) > 0 else Fore.BLUE
)
echo(f"{lint_success_color}{lint_success_message}{Style.RESET_ALL}")
if config.stdin is False or config.lint:
if print_blanks:
echo()
return lint_error_count + format_error_count
@ -100,7 +106,7 @@ def build_output(error: dict, config: Config) -> int:
filename = build_relative_path(list(error.keys())[0], config.project_root.resolve())
if "{filename}" not in config.linter_output_format:
if "{filename}" not in config.linter_output_format and not config.stdin:
echo(
f"{Fore.GREEN}{Style.BRIGHT}\n{filename}\n{Style.DIM}"
+ "".join(["" for x in range(1, width)])
@ -140,16 +146,7 @@ def build_check_output(errors: dict, config: Config) -> int:
color = {"-": Fore.YELLOW, "+": Fore.GREEN, "@": Style.BRIGHT + Fore.BLUE}
width, _ = shutil.get_terminal_size()
if config.quiet is True and len(list(errors.values())[0]) > 0:
echo(
Fore.GREEN
+ Style.BRIGHT
+ build_relative_path(list(errors.keys())[0], config.project_root.resolve())
+ Style.DIM
+ Style.RESET_ALL
)
elif config.quiet is False and len(list(errors.values())[0]) > 0:
if config.quiet is False and len(list(errors.values())[0]) > 0:
echo(
Fore.GREEN
+ Style.BRIGHT

View file

@ -174,7 +174,7 @@ def test_check_reformatter_simple_error_quiet(
write_to_file(tmp_file.name, b"<div><p>nice stuff here</p></div>")
result = runner.invoke(djlint, [tmp_file.name, "--check", "--quiet"])
assert result.exit_code == 1
assert "1 file would be updated." in result.output
assert "1 file would be updated." not in result.output
def test_check_reformatter_no_error(runner: CliRunner, tmp_file: TextIO) -> None: