mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Consolidate arguments for run()
This commit is contained in:
parent
6a1f945e31
commit
8aa88c7363
1 changed files with 15 additions and 30 deletions
|
|
@ -19,8 +19,8 @@ COLS = int(subprocess.Popen(['tput', 'cols'], stdout=subprocess.PIPE).communicat
|
||||||
PASS_FAIL_LENGTH = 6
|
PASS_FAIL_LENGTH = 6
|
||||||
|
|
||||||
|
|
||||||
def _run_single_hook(runner, repository, hook_id, all_files=False, verbose=False):
|
def _run_single_hook(runner, repository, hook_id, args):
|
||||||
if all_files:
|
if args.all_files:
|
||||||
get_filenames = git.get_all_files_matching
|
get_filenames = git.get_all_files_matching
|
||||||
else:
|
else:
|
||||||
get_filenames = git.get_staged_files_matching
|
get_filenames = git.get_staged_files_matching
|
||||||
|
|
@ -56,44 +56,39 @@ def _run_single_hook(runner, repository, hook_id, all_files=False, verbose=False
|
||||||
|
|
||||||
print('{0}{1}{2}'.format(color, pass_fail, NORMAL))
|
print('{0}{1}{2}'.format(color, pass_fail, NORMAL))
|
||||||
|
|
||||||
if output and (retcode or verbose):
|
if output and (retcode or args.verbose):
|
||||||
print('\n' + output)
|
print('\n' + output)
|
||||||
|
|
||||||
return retcode
|
return retcode
|
||||||
|
|
||||||
|
|
||||||
def run_hooks(runner, all_files=False, verbose=False):
|
def run_hooks(runner, args):
|
||||||
"""Actually run the hooks."""
|
"""Actually run the hooks."""
|
||||||
retval = 0
|
retval = 0
|
||||||
|
|
||||||
for repo in runner.repositories:
|
for repo in runner.repositories:
|
||||||
for hook_id in repo.hooks:
|
for hook_id in repo.hooks:
|
||||||
retval |= _run_single_hook(
|
retval |= _run_single_hook(runner, repo, hook_id, args)
|
||||||
runner,
|
|
||||||
repo,
|
|
||||||
hook_id,
|
|
||||||
all_files=all_files,
|
|
||||||
verbose=verbose,
|
|
||||||
)
|
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
||||||
def run_single_hook(runner, hook_id, all_files=False, verbose=False):
|
def run_single_hook(runner, hook_id, args):
|
||||||
for repo in runner.repositories:
|
for repo in runner.repositories:
|
||||||
if hook_id in repo.hooks:
|
if hook_id in repo.hooks:
|
||||||
return _run_single_hook(
|
return _run_single_hook(runner, repo, hook_id, args)
|
||||||
runner,
|
|
||||||
repo,
|
|
||||||
hook_id,
|
|
||||||
all_files=all_files,
|
|
||||||
verbose=verbose,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
print('No hook with id `{0}`'.format(hook_id))
|
print('No hook with id `{0}`'.format(hook_id))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
def _run(runner, args):
|
||||||
|
if args.hook:
|
||||||
|
return run_single_hook(runner, args.hook, args)
|
||||||
|
else:
|
||||||
|
return run_hooks(runner, args)
|
||||||
|
|
||||||
|
|
||||||
@entry
|
@entry
|
||||||
def run(argv):
|
def run(argv):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
@ -135,17 +130,7 @@ def run(argv):
|
||||||
elif args.command == 'autoupdate':
|
elif args.command == 'autoupdate':
|
||||||
return commands.autoupdate(runner)
|
return commands.autoupdate(runner)
|
||||||
elif args.command == 'run':
|
elif args.command == 'run':
|
||||||
if args.hook:
|
return _run(runner, args)
|
||||||
return run_single_hook(
|
|
||||||
runner,
|
|
||||||
args.hook,
|
|
||||||
all_files=args.all_files,
|
|
||||||
verbose=args.verbose,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return run_hooks(
|
|
||||||
runner, all_files=args.all_files, verbose=args.verbose,
|
|
||||||
)
|
|
||||||
elif args.command == 'help':
|
elif args.command == 'help':
|
||||||
if args.help_cmd:
|
if args.help_cmd:
|
||||||
parser.parse_args([args.help_cmd, '--help'])
|
parser.parse_args([args.help_cmd, '--help'])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue