mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
DRY up validate_*
This commit is contained in:
parent
9ce6cc6c05
commit
9a1799b9a8
3 changed files with 34 additions and 44 deletions
|
|
@ -1,12 +1,9 @@
|
|||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
|
||||
from pre_commit.clientlib.validate_base import get_run_function
|
||||
from pre_commit.clientlib.validate_base import get_validator
|
||||
from pre_commit.util import entry
|
||||
|
||||
|
||||
class InvalidConfigError(ValueError): pass
|
||||
|
|
@ -69,24 +66,7 @@ load_config = get_validator(
|
|||
)
|
||||
|
||||
|
||||
@entry
|
||||
def run(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Config filenames.')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retval = 0
|
||||
for filename in args.filenames:
|
||||
try:
|
||||
load_config(filename)
|
||||
except InvalidConfigError as e:
|
||||
print(e.args[0])
|
||||
# If we have more than one exception argument print the stringified
|
||||
# version
|
||||
if len(e.args) > 1:
|
||||
print(str(e.args[1]))
|
||||
retval = 1
|
||||
return retval
|
||||
run = get_run_function('Config filenames.', load_config, InvalidConfigError)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue