forked from Lucas-C/pre-commit-hooks-safety
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,47 @@ | ||
from __future__ import print_function | ||
|
||
import argparse | ||
import sys | ||
|
||
from safety.cli import check | ||
|
||
|
||
def _parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--full-report", | ||
default="--full-report", | ||
const="--full-report", | ||
action="store_const", | ||
) | ||
parser.add_argument( | ||
"--short-report", | ||
dest="full_report", | ||
const="--short-report", | ||
action="store_const", | ||
) | ||
parser.add_argument("--ignore", "-i", action="append") | ||
parser.add_argument("files", nargs="+") | ||
return parser | ||
|
||
|
||
def main(argv=None): | ||
if argv is None: | ||
argv = sys.argv[1:] | ||
parsed_args, rest = _parser().parse_known_args(argv) | ||
ignore = [ | ||
arg | ||
for vs in parsed_args.ignore or [] | ||
for code in vs.split(",") | ||
for arg in ("--ignore", code.strip()) | ||
] | ||
files = [arg for f in parsed_args.files for arg in ("--file", f)] | ||
args = [parsed_args.full_report] + ignore + files + rest | ||
try: | ||
check.main(['--full-report'] + sum(([arg] if arg.startswith('-') else ['--file', arg] for arg in argv), [])) | ||
return 0 | ||
check.main(args) | ||
except SystemExit as error: | ||
if error.code == 0: | ||
return 0 | ||
return 1 | ||
return 1 | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
sys.exit(main()) |