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,10 +1,14 @@
|
|||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import jsonschema
|
||||
import jsonschema.exceptions
|
||||
import os.path
|
||||
import yaml
|
||||
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.util import entry
|
||||
|
||||
|
||||
def get_validator(
|
||||
|
|
@ -48,3 +52,25 @@ def get_validator(
|
|||
return obj
|
||||
|
||||
return validate
|
||||
|
||||
|
||||
def get_run_function(filenames_help, validate_strategy, exception_cls):
|
||||
@entry
|
||||
def run(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help=filenames_help)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retval = 0
|
||||
for filename in args.filenames:
|
||||
try:
|
||||
validate_strategy(filename)
|
||||
except exception_cls as e:
|
||||
print(e.args[0])
|
||||
# If there was an inner exception, print the stringified
|
||||
# version of that.
|
||||
if len(e.args) > 1:
|
||||
print(str(e.args[1]))
|
||||
retval = 1
|
||||
return retval
|
||||
return run
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue