From 526bc3aca201dee45e3b74d0873f05d7321e9583 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 10 Aug 2021 21:59:20 +0200 Subject: Add -F / --file --- pygitchecker.py | 25 ++++++++++++++++++------- 1 file 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 @@ """Simple, on demand git checker""" import argparse import errno +import io import json import os import subprocess @@ -147,11 +148,18 @@ def main(inargs=None): help='Continue with the checks if validation fails') parser.add_argument( '-c', '--config', - metavar='FILE', + metavar='', type=str, default=os.path.expanduser('~/.pygitchecker.json'), dest='config_file', help='Config file (default: ~/.pygitchecker.json)') + parser.add_argument( + '-F', '--file', + metavar='', + type=str, + default='', + dest='python_file', + help='Validate a particular .py file') parser.add_argument( '-f', '--full', action='store_true', @@ -178,6 +186,15 @@ def main(inargs=None): dest='verbose', help='Verbosity') args = parser.parse_args(inargs) + try: + with io.open(args.config_file, 'r') as fp: + config_dict = json.load(fp) + except Exception as e: + eprint(f'Unable to parse {args.config_file}: {e}') + sys.exit(errno.EIO) + if args.python_file: + validate_python_file(args.python_file, config_dict.get('tests'), args) + sys.exit(0) abs_repo_path = os.path.abspath(os.path.expanduser(args.repo_path)) if args.mod_only: if not args.recursive: @@ -207,12 +224,6 @@ def main(inargs=None): print('No files selected') sys.exit(0) # now run the real tests - try: - with open(args.config_file, 'r') as fp: - config_dict = json.load(fp) - except Exception as e: - eprint(f'Unable to parse {args.config_file}: {e}') - sys.exit(errno.EIO) for target_file in selected_files: if args.list_only: print(target_file) -- cgit v1.3