mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 02:21:46 +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,10 +137,12 @@ def _run_single_hook(
|
||||||
diff_before: bytes,
|
diff_before: bytes,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
use_color: bool,
|
use_color: bool,
|
||||||
|
quiet: bool,
|
||||||
) -> Tuple[bool, bytes]:
|
) -> Tuple[bool, bytes]:
|
||||||
filenames = classifier.filenames_for_hook(hook)
|
filenames = classifier.filenames_for_hook(hook)
|
||||||
|
|
||||||
if hook.id in skips or hook.alias in skips:
|
if hook.id in skips or hook.alias in skips:
|
||||||
|
if not quiet:
|
||||||
output.write(
|
output.write(
|
||||||
_full_msg(
|
_full_msg(
|
||||||
start=hook.name,
|
start=hook.name,
|
||||||
|
|
@ -156,6 +158,7 @@ def _run_single_hook(
|
||||||
files_modified = False
|
files_modified = False
|
||||||
out = b''
|
out = b''
|
||||||
elif not filenames and not hook.always_run:
|
elif not filenames and not hook.always_run:
|
||||||
|
if not quiet:
|
||||||
output.write(
|
output.write(
|
||||||
_full_msg(
|
_full_msg(
|
||||||
start=hook.name,
|
start=hook.name,
|
||||||
|
|
@ -272,6 +275,7 @@ def _run_hooks(
|
||||||
current_retval, prior_diff = _run_single_hook(
|
current_retval, prior_diff = _run_single_hook(
|
||||||
classifier, hook, skips, cols, prior_diff,
|
classifier, hook, skips, cols, prior_diff,
|
||||||
verbose=args.verbose, use_color=args.color,
|
verbose=args.verbose, use_color=args.color,
|
||||||
|
quiet=False if args.verbose else args.quiet,
|
||||||
)
|
)
|
||||||
retval |= current_retval
|
retval |= current_retval
|
||||||
if retval and config['fail_fast']:
|
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:
|
def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
||||||
parser.add_argument('hook', nargs='?', help='A single hook-id to run')
|
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('--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 = parser.add_mutually_exclusive_group(required=False)
|
||||||
mutex_group.add_argument(
|
mutex_group.add_argument(
|
||||||
'--all-files', '-a', action='store_true', default=False,
|
'--all-files', '-a', action='store_true', default=False,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue