From f66ea8d546e1cd4adf205a6b4764da9146934794 Mon Sep 17 00:00:00 2001 From: Chris Kuehl Date: Sun, 1 Nov 2015 01:05:39 -0700 Subject: [PATCH] Add simple identify command --- pre_commit/commands/identify.py | 8 ++++++++ pre_commit/main.py | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 pre_commit/commands/identify.py diff --git a/pre_commit/commands/identify.py b/pre_commit/commands/identify.py new file mode 100644 index 00000000..f1ec0ce6 --- /dev/null +++ b/pre_commit/commands/identify.py @@ -0,0 +1,8 @@ +from pre_commit import git +from pre_commit.file_classifier.classifier import classify + + +def identify(args): + # TODO: more useful output + # TODO: check whether file is in git repo first? + print(classify(args.path, git.guess_git_type_for_file(args.path))) diff --git a/pre_commit/main.py b/pre_commit/main.py index ce16acde..132e901a 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -10,6 +10,7 @@ from pre_commit import color from pre_commit import five from pre_commit.commands.autoupdate import autoupdate from pre_commit.commands.clean import clean +from pre_commit.commands.identify import identify from pre_commit.commands.install_uninstall import install from pre_commit.commands.install_uninstall import uninstall from pre_commit.commands.run import run @@ -67,6 +68,11 @@ def main(argv=None): default='pre-commit', ) + identify_parser = subparsers.add_parser( + 'identify', help='Identify a file, listing tags that apply to it', + ) + identify_parser.add_argument('path') + subparsers.add_parser('clean', help='Clean out pre-commit files.') subparsers.add_parser( @@ -145,6 +151,8 @@ def main(argv=None): return autoupdate(runner) elif args.command == 'run': return run(runner, args) + elif args.command == 'identify': + return identify(args) else: raise NotImplementedError( 'Command {0} not implemented.'.format(args.command)