diff --git a/bin/git-lint b/bin/git-lint new file mode 100755 index 0000000..b0891fd --- /dev/null +++ b/bin/git-lint @@ -0,0 +1,39 @@ +#!/usr/bin/env python +import git_lint + +def main(*args): + if git_lint.git_base is None: + sys.exit(_('A git repository was not found.')) + + (cmdline, filenames, excluded_commands) = git_lint.make_rational_options(git_lint.OPTIONS_LIST, args) + + if len(excluded_commands) > 0: + print(_('These command line options were ignored due to option precedence.')) + for exc in excluded_commands: + print("\t{}".format(exc)) + + try: + config = git_lint.get_config(cmdline, git_lint.git_base) + + if 'help' in cmdline: + git_lint.print_help(OPTIONS_LIST, NAME) + return 0 + + if 'version' in cmdline: + git_lint.print_version(NAME, VERSION) + return 0 + + if 'linters' in cmdline: + git_lint.print_linters(config) + return 0 + + return git_lint.run_gitlint(cmdline, config, filenames) + + except getopt.GetoptError as err: + git_lint.print_help(OPTIONS_LIST) + return 1 + + +if __name__ == '__main__': + import sys + sys.exit(main(*sys.argv)) diff --git a/git_lint/git_lint.py b/git_lint/git_lint.py index c6e4922..af23974 100644 --- a/git_lint/git_lint.py +++ b/git_lint/git_lint.py @@ -641,39 +641,3 @@ def print_version(name, version): print('{} {} Copyright (c) 2009, 2016 Kennth M. "Elf" Sternberg'.format(name, version)) -def main(*args): - if git_base is None: - sys.exit(_('A git repository was not found.')) - - (cmdline, filenames, excluded_commands) = make_rational_options(OPTIONS_LIST, args) - - if len(excluded_commands) > 0: - print(_('These command line options were ignored due to option precedence.')) - for exc in excluded_commands: - print("\t{}".format(exc)) - - try: - config = get_config(cmdline, git_base) - - if 'help' in cmdline: - print_help(OPTIONS_LIST, NAME) - return 0 - - if 'version' in cmdline: - print_version(NAME, VERSION) - return 0 - - if 'linters' in cmdline: - print_linters(config) - return 0 - - return run_gitlint(cmdline, config, filenames) - - except getopt.GetoptError as err: - print_help(OPTIONS_LIST) - return 1 - - -if __name__ == '__main__': - import sys - sys.exit(main(*sys.argv))