|
19 | 19 | PASS_FAIL_LENGTH = 6 |
20 | 20 |
|
21 | 21 |
|
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: |
24 | 24 | get_filenames = git.get_all_files_matching |
25 | 25 | else: |
26 | 26 | get_filenames = git.get_staged_files_matching |
@@ -56,44 +56,39 @@ def _run_single_hook(runner, repository, hook_id, all_files=False, verbose=False |
56 | 56 |
|
57 | 57 | print('{0}{1}{2}'.format(color, pass_fail, NORMAL)) |
58 | 58 |
|
59 | | - if output and (retcode or verbose): |
| 59 | + if output and (retcode or args.verbose): |
60 | 60 | print('\n' + output) |
61 | 61 |
|
62 | 62 | return retcode |
63 | 63 |
|
64 | 64 |
|
65 | | -def run_hooks(runner, all_files=False, verbose=False): |
| 65 | +def run_hooks(runner, args): |
66 | 66 | """Actually run the hooks.""" |
67 | 67 | retval = 0 |
68 | 68 |
|
69 | 69 | for repo in runner.repositories: |
70 | 70 | 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) |
78 | 72 |
|
79 | 73 | return retval |
80 | 74 |
|
81 | 75 |
|
82 | | -def run_single_hook(runner, hook_id, all_files=False, verbose=False): |
| 76 | +def run_single_hook(runner, hook_id, args): |
83 | 77 | for repo in runner.repositories: |
84 | 78 | 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) |
92 | 80 | else: |
93 | 81 | print('No hook with id `{0}`'.format(hook_id)) |
94 | 82 | return 1 |
95 | 83 |
|
96 | 84 |
|
| 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 | + |
97 | 92 | @entry |
98 | 93 | def run(argv): |
99 | 94 | parser = argparse.ArgumentParser() |
@@ -135,17 +130,7 @@ def run(argv): |
135 | 130 | elif args.command == 'autoupdate': |
136 | 131 | return commands.autoupdate(runner) |
137 | 132 | 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) |
149 | 134 | elif args.command == 'help': |
150 | 135 | if args.help_cmd: |
151 | 136 | parser.parse_args([args.help_cmd, '--help']) |
|
0 commit comments