|
21 | 21 | from pre_commit.commands.run import run |
22 | 22 | from pre_commit.commands.sample_config import sample_config |
23 | 23 | from pre_commit.commands.try_repo import try_repo |
| 24 | +from pre_commit.commands.validate_config import validate_config |
| 25 | +from pre_commit.commands.validate_manifest import validate_manifest |
24 | 26 | from pre_commit.error_handler import error_handler |
25 | 27 | from pre_commit.logging_handler import logging_handler |
26 | 28 | from pre_commit.store import Store |
|
34 | 36 | # pyvenv |
35 | 37 | os.environ.pop('__PYVENV_LAUNCHER__', None) |
36 | 38 |
|
37 | | - |
38 | | -COMMANDS_NO_GIT = {'clean', 'gc', 'init-templatedir', 'sample-config'} |
| 39 | +COMMANDS_NO_GIT = { |
| 40 | + 'clean', 'gc', 'init-templatedir', 'sample-config', |
| 41 | + 'validate-config', 'validate-manifest', |
| 42 | +} |
39 | 43 |
|
40 | 44 |
|
41 | 45 | def _add_config_option(parser: argparse.ArgumentParser) -> None: |
@@ -304,6 +308,20 @@ def main(argv: Sequence[str] | None = None) -> int: |
304 | 308 | _add_config_option(uninstall_parser) |
305 | 309 | _add_hook_type_option(uninstall_parser) |
306 | 310 |
|
| 311 | + validate_config_parser = subparsers.add_parser( |
| 312 | + 'validate-config', help='Validate .pre-commit-config.yaml files', |
| 313 | + ) |
| 314 | + add_color_option(validate_config_parser) |
| 315 | + _add_config_option(validate_config_parser) |
| 316 | + validate_config_parser.add_argument('filenames', nargs='*') |
| 317 | + |
| 318 | + validate_manifest_parser = subparsers.add_parser( |
| 319 | + 'validate-manifest', help='Validate .pre-commit-hooks.yaml files', |
| 320 | + ) |
| 321 | + add_color_option(validate_manifest_parser) |
| 322 | + _add_config_option(validate_manifest_parser) |
| 323 | + validate_manifest_parser.add_argument('filenames', nargs='*') |
| 324 | + |
307 | 325 | help = subparsers.add_parser( |
308 | 326 | 'help', help='Show help for a specific command.', |
309 | 327 | ) |
@@ -378,6 +396,10 @@ def main(argv: Sequence[str] | None = None) -> int: |
378 | 396 | config_file=args.config, |
379 | 397 | hook_types=args.hook_types, |
380 | 398 | ) |
| 399 | + elif args.command == 'validate-config': |
| 400 | + return validate_config(args.filenames) |
| 401 | + elif args.command == 'validate-manifest': |
| 402 | + return validate_manifest(args.filenames) |
381 | 403 | else: |
382 | 404 | raise NotImplementedError( |
383 | 405 | f'Command {args.command} not implemented.', |
|
0 commit comments