summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpygitchecker.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/pygitchecker.py b/pygitchecker.py
index b9041c1..6af9e0e 100755
--- a/pygitchecker.py
+++ b/pygitchecker.py
@@ -3,6 +3,7 @@
3"""Simple, on demand git checker""" 3"""Simple, on demand git checker"""
4import argparse 4import argparse
5import errno 5import errno
6import io
6import json 7import json
7import os 8import os
8import subprocess 9import subprocess
@@ -147,12 +148,19 @@ def main(inargs=None):
147 help='Continue with the checks if validation fails') 148 help='Continue with the checks if validation fails')
148 parser.add_argument( 149 parser.add_argument(
149 '-c', '--config', 150 '-c', '--config',
150 metavar='FILE', 151 metavar='<file>',
151 type=str, 152 type=str,
152 default=os.path.expanduser('~/.pygitchecker.json'), 153 default=os.path.expanduser('~/.pygitchecker.json'),
153 dest='config_file', 154 dest='config_file',
154 help='Config file (default: ~/.pygitchecker.json)') 155 help='Config file (default: ~/.pygitchecker.json)')
155 parser.add_argument( 156 parser.add_argument(
157 '-F', '--file',
158 metavar='<file>',
159 type=str,
160 default='',
161 dest='python_file',
162 help='Validate a particular .py file')
163 parser.add_argument(
156 '-f', '--full', 164 '-f', '--full',
157 action='store_true', 165 action='store_true',
158 dest='full_search', 166 dest='full_search',
@@ -178,6 +186,15 @@ def main(inargs=None):
178 dest='verbose', 186 dest='verbose',
179 help='Verbosity') 187 help='Verbosity')
180 args = parser.parse_args(inargs) 188 args = parser.parse_args(inargs)
189 try:
190 with io.open(args.config_file, 'r') as fp:
191 config_dict = json.load(fp)
192 except Exception as e:
193 eprint(f'Unable to parse {args.config_file}: {e}')
194 sys.exit(errno.EIO)
195 if args.python_file:
196 validate_python_file(args.python_file, config_dict.get('tests'), args)
197 sys.exit(0)
181 abs_repo_path = os.path.abspath(os.path.expanduser(args.repo_path)) 198 abs_repo_path = os.path.abspath(os.path.expanduser(args.repo_path))
182 if args.mod_only: 199 if args.mod_only:
183 if not args.recursive: 200 if not args.recursive:
@@ -207,12 +224,6 @@ def main(inargs=None):
207 print('No files selected') 224 print('No files selected')
208 sys.exit(0) 225 sys.exit(0)
209 # now run the real tests 226 # now run the real tests
210 try:
211 with open(args.config_file, 'r') as fp:
212 config_dict = json.load(fp)
213 except Exception as e:
214 eprint(f'Unable to parse {args.config_file}: {e}')
215 sys.exit(errno.EIO)
216 for target_file in selected_files: 227 for target_file in selected_files:
217 if args.list_only: 228 if args.list_only:
218 print(target_file) 229 print(target_file)