mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Implement quiet mode, silent on skipped hooks
This commit is contained in:
parent
f1de792877
commit
89d88f7ebc
2 changed files with 27 additions and 19 deletions
|
|
@ -137,35 +137,38 @@ def _run_single_hook(
|
|||
diff_before: bytes,
|
||||
verbose: bool,
|
||||
use_color: bool,
|
||||
quiet: bool,
|
||||
) -> Tuple[bool, bytes]:
|
||||
filenames = classifier.filenames_for_hook(hook)
|
||||
|
||||
if hook.id in skips or hook.alias in skips:
|
||||
output.write(
|
||||
_full_msg(
|
||||
start=hook.name,
|
||||
end_msg=SKIPPED,
|
||||
end_color=color.YELLOW,
|
||||
use_color=use_color,
|
||||
cols=cols,
|
||||
),
|
||||
)
|
||||
if not quiet:
|
||||
output.write(
|
||||
_full_msg(
|
||||
start=hook.name,
|
||||
end_msg=SKIPPED,
|
||||
end_color=color.YELLOW,
|
||||
use_color=use_color,
|
||||
cols=cols,
|
||||
),
|
||||
)
|
||||
duration = None
|
||||
retcode = 0
|
||||
diff_after = diff_before
|
||||
files_modified = False
|
||||
out = b''
|
||||
elif not filenames and not hook.always_run:
|
||||
output.write(
|
||||
_full_msg(
|
||||
start=hook.name,
|
||||
postfix=NO_FILES,
|
||||
end_msg=SKIPPED,
|
||||
end_color=color.TURQUOISE,
|
||||
use_color=use_color,
|
||||
cols=cols,
|
||||
),
|
||||
)
|
||||
if not quiet:
|
||||
output.write(
|
||||
_full_msg(
|
||||
start=hook.name,
|
||||
postfix=NO_FILES,
|
||||
end_msg=SKIPPED,
|
||||
end_color=color.TURQUOISE,
|
||||
use_color=use_color,
|
||||
cols=cols,
|
||||
),
|
||||
)
|
||||
duration = None
|
||||
retcode = 0
|
||||
diff_after = diff_before
|
||||
|
|
@ -272,6 +275,7 @@ def _run_hooks(
|
|||
current_retval, prior_diff = _run_single_hook(
|
||||
classifier, hook, skips, cols, prior_diff,
|
||||
verbose=args.verbose, use_color=args.color,
|
||||
quiet=False if args.verbose else args.quiet,
|
||||
)
|
||||
retval |= current_retval
|
||||
if retval and config['fail_fast']:
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ def _add_hook_type_option(parser: argparse.ArgumentParser) -> None:
|
|||
def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
||||
parser.add_argument('hook', nargs='?', help='A single hook-id to run')
|
||||
parser.add_argument('--verbose', '-v', action='store_true', default=False)
|
||||
parser.add_argument(
|
||||
'--quiet', '-q', action='store_true', default=False,
|
||||
help='Enable quiet mode (verbose mode overrides this).',
|
||||
)
|
||||
mutex_group = parser.add_mutually_exclusive_group(required=False)
|
||||
mutex_group.add_argument(
|
||||
'--all-files', '-a', action='store_true', default=False,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue