|
2 | 2 |
|
3 | 3 | import argparse |
4 | 4 | import pkg_resources |
| 5 | +import sys |
5 | 6 |
|
6 | 7 | from pre_commit import color |
7 | 8 | from pre_commit.commands.autoupdate import autoupdate |
8 | 9 | from pre_commit.commands.clean import clean |
9 | 10 | from pre_commit.commands.install_uninstall import install |
10 | 11 | from pre_commit.commands.install_uninstall import uninstall |
11 | 12 | from pre_commit.commands.run import run |
| 13 | +from pre_commit.error_handler import error_handler |
12 | 14 | from pre_commit.runner import Runner |
13 | | -from pre_commit.util import entry |
14 | 15 |
|
15 | 16 |
|
16 | | -@entry |
17 | | -def main(argv): |
| 17 | +def main(argv=None): |
| 18 | + argv = argv if argv is not None else sys.argv[1:] |
18 | 19 | parser = argparse.ArgumentParser() |
19 | 20 |
|
20 | 21 | # http://stackoverflow.com/a/8521644/812183 |
@@ -83,29 +84,30 @@ def main(argv): |
83 | 84 | else: |
84 | 85 | parser.parse_args(['--help']) |
85 | 86 |
|
86 | | - runner = Runner.create() |
| 87 | + with error_handler(): |
| 88 | + runner = Runner.create() |
| 89 | + |
| 90 | + if args.command == 'install': |
| 91 | + return install( |
| 92 | + runner, overwrite=args.overwrite, hooks=args.install_hooks, |
| 93 | + ) |
| 94 | + elif args.command == 'uninstall': |
| 95 | + return uninstall(runner) |
| 96 | + elif args.command == 'clean': |
| 97 | + return clean(runner) |
| 98 | + elif args.command == 'autoupdate': |
| 99 | + return autoupdate(runner) |
| 100 | + elif args.command == 'run': |
| 101 | + return run(runner, args) |
| 102 | + else: |
| 103 | + raise NotImplementedError( |
| 104 | + 'Command {0} not implemented.'.format(args.command) |
| 105 | + ) |
87 | 106 |
|
88 | | - if args.command == 'install': |
89 | | - return install( |
90 | | - runner, overwrite=args.overwrite, hooks=args.install_hooks, |
91 | | - ) |
92 | | - elif args.command == 'uninstall': |
93 | | - return uninstall(runner) |
94 | | - elif args.command == 'clean': |
95 | | - return clean(runner) |
96 | | - elif args.command == 'autoupdate': |
97 | | - return autoupdate(runner) |
98 | | - elif args.command == 'run': |
99 | | - return run(runner, args) |
100 | | - else: |
101 | | - raise NotImplementedError( |
102 | | - 'Command {0} not implemented.'.format(args.command) |
| 107 | + raise AssertionError( |
| 108 | + 'Command {0} failed to exit with a returncode'.format(args.command) |
103 | 109 | ) |
104 | 110 |
|
105 | | - raise AssertionError( |
106 | | - 'Command {0} failed to exit with a returncode'.format(args.command) |
107 | | - ) |
108 | | - |
109 | 111 |
|
110 | 112 | if __name__ == '__main__': |
111 | 113 | exit(main()) |
0 commit comments