Skip to content

Commit 8aa88c7

Browse files
committed
Consolidate arguments for run()
1 parent 6a1f945 commit 8aa88c7

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

pre_commit/run.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
PASS_FAIL_LENGTH = 6
2020

2121

22-
def _run_single_hook(runner, repository, hook_id, all_files=False, verbose=False):
23-
if all_files:
22+
def _run_single_hook(runner, repository, hook_id, args):
23+
if args.all_files:
2424
get_filenames = git.get_all_files_matching
2525
else:
2626
get_filenames = git.get_staged_files_matching
@@ -56,44 +56,39 @@ def _run_single_hook(runner, repository, hook_id, all_files=False, verbose=False
5656

5757
print('{0}{1}{2}'.format(color, pass_fail, NORMAL))
5858

59-
if output and (retcode or verbose):
59+
if output and (retcode or args.verbose):
6060
print('\n' + output)
6161

6262
return retcode
6363

6464

65-
def run_hooks(runner, all_files=False, verbose=False):
65+
def run_hooks(runner, args):
6666
"""Actually run the hooks."""
6767
retval = 0
6868

6969
for repo in runner.repositories:
7070
for hook_id in repo.hooks:
71-
retval |= _run_single_hook(
72-
runner,
73-
repo,
74-
hook_id,
75-
all_files=all_files,
76-
verbose=verbose,
77-
)
71+
retval |= _run_single_hook(runner, repo, hook_id, args)
7872

7973
return retval
8074

8175

82-
def run_single_hook(runner, hook_id, all_files=False, verbose=False):
76+
def run_single_hook(runner, hook_id, args):
8377
for repo in runner.repositories:
8478
if hook_id in repo.hooks:
85-
return _run_single_hook(
86-
runner,
87-
repo,
88-
hook_id,
89-
all_files=all_files,
90-
verbose=verbose,
91-
)
79+
return _run_single_hook(runner, repo, hook_id, args)
9280
else:
9381
print('No hook with id `{0}`'.format(hook_id))
9482
return 1
9583

9684

85+
def _run(runner, args):
86+
if args.hook:
87+
return run_single_hook(runner, args.hook, args)
88+
else:
89+
return run_hooks(runner, args)
90+
91+
9792
@entry
9893
def run(argv):
9994
parser = argparse.ArgumentParser()
@@ -135,17 +130,7 @@ def run(argv):
135130
elif args.command == 'autoupdate':
136131
return commands.autoupdate(runner)
137132
elif args.command == 'run':
138-
if args.hook:
139-
return run_single_hook(
140-
runner,
141-
args.hook,
142-
all_files=args.all_files,
143-
verbose=args.verbose,
144-
)
145-
else:
146-
return run_hooks(
147-
runner, all_files=args.all_files, verbose=args.verbose,
148-
)
133+
return _run(runner, args)
149134
elif args.command == 'help':
150135
if args.help_cmd:
151136
parser.parse_args([args.help_cmd, '--help'])

0 commit comments

Comments
 (0)