mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Minor improvements to pre_commit/run.py
This commit is contained in:
parent
e0d02da6a4
commit
6b1097d3c9
1 changed files with 13 additions and 15 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
from pre_commit import git
|
from pre_commit import git
|
||||||
from pre_commit.clientlib.validate_config import validate_config
|
from pre_commit.clientlib.validate_config import validate_config
|
||||||
|
|
@ -14,16 +15,6 @@ NORMAL = '\033[0m'
|
||||||
COLS = int(subprocess.Popen(['tput', 'cols'], stdout=subprocess.PIPE).communicate()[0])
|
COLS = int(subprocess.Popen(['tput', 'cols'], stdout=subprocess.PIPE).communicate()[0])
|
||||||
|
|
||||||
|
|
||||||
def install():
|
|
||||||
"""Install the pre-commit hook."""
|
|
||||||
git.create_pre_commit()
|
|
||||||
|
|
||||||
|
|
||||||
def uninstall():
|
|
||||||
"""Uninstall the pre-commit hook."""
|
|
||||||
git.remove_pre_commit()
|
|
||||||
|
|
||||||
|
|
||||||
def _run_single_hook(repository, hook_id, run_all_the_things=False):
|
def _run_single_hook(repository, hook_id, run_all_the_things=False):
|
||||||
repository.install()
|
repository.install()
|
||||||
|
|
||||||
|
|
@ -95,7 +86,7 @@ def run_single_hook(hook_id, configs=None, run_all_the_things=False):
|
||||||
run_all_the_things=run_all_the_things,
|
run_all_the_things=run_all_the_things,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print "No hook with id {0}".format(hook_id)
|
print 'No hook with id {0}'.format(hook_id)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -114,8 +105,7 @@ def run(argv):
|
||||||
help='Uninstall the pre-commit script.',
|
help='Uninstall the pre-commit script.',
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
'-r', '--run',
|
'-r', '--run', metavar='HOOK', help='Run a single hook.',
|
||||||
help='Run a hook'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -126,10 +116,18 @@ def run(argv):
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
if args.install:
|
if args.install:
|
||||||
return install()
|
git.create_pre_commit()
|
||||||
|
print 'pre-commit installed at {0}'.format(git.get_pre_commit_path())
|
||||||
|
return 0
|
||||||
elif args.uninstall:
|
elif args.uninstall:
|
||||||
return uninstall()
|
git.remove_pre_commit()
|
||||||
|
print 'pre-commit uninstalled'
|
||||||
|
return 0
|
||||||
elif args.run:
|
elif args.run:
|
||||||
return run_single_hook(args.run, run_all_the_things=args.run_fucking_everything)
|
return run_single_hook(args.run, run_all_the_things=args.run_fucking_everything)
|
||||||
else:
|
else:
|
||||||
return run_hooks(run_all_the_things=args.run_fucking_everything)
|
return run_hooks(run_all_the_things=args.run_fucking_everything)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run(sys.argv[1:])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue