diff options
| author | Simeon Simeonov | 2021-08-10 21:59:20 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2021-08-10 21:59:20 +0200 |
| commit | 526bc3aca201dee45e3b74d0873f05d7321e9583 (patch) | |
| tree | 5e3fcc9efe87ed2d4b34dc2c0bf15046707f4ed4 | |
| parent | cb7c844e774b1a7d64db54327fa27c8c9f702d2e (diff) | |
Add -F / --file
| -rwxr-xr-x | pygitchecker.py | 25 |
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""" |
| 4 | import argparse | 4 | import argparse |
| 5 | import errno | 5 | import errno |
| 6 | import io | ||
| 6 | import json | 7 | import json |
| 7 | import os | 8 | import os |
| 8 | import subprocess | 9 | import 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) |
