Implement quiet mode, silent on skipped hooks

This commit is contained in:
Peter Cock 2020-08-15 13:54:57 +01:00
parent f1de792877
commit 89d88f7ebc
2 changed files with 27 additions and 19 deletions

View file

@ -137,10 +137,12 @@ 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:
if not quiet:
output.write(
_full_msg(
start=hook.name,
@ -156,6 +158,7 @@ def _run_single_hook(
files_modified = False
out = b''
elif not filenames and not hook.always_run:
if not quiet:
output.write(
_full_msg(
start=hook.name,
@ -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']:

View file

@ -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,