forked from ajinabraham/nodejsscan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
55 lines (50 loc) · 1.77 KB
/
Copy pathcli.py
File metadata and controls
55 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf_8 -*-
"""
nodejsscan cli
"""
import json
import argparse
from core.scanner import scan_dirs, scan_file
import core.settings as settings
def output(out, scan_results):
"""Output"""
if out:
# out is the fully qualified path and filename for the ouptput file. We recommend you use a .json extension
with open(out, 'w') as outfile:
json.dump(scan_results, outfile, sort_keys=True,
indent=4, separators=(',', ': '))
else:
print((json.dumps(scan_results, sort_keys=True,
indent=4, separators=(',', ': '))))
def main():
"""Main CLI"""
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file",
nargs='+',
help="Node.js file(s) to scan",
required=False)
parser.add_argument("-d", "--directory",
nargs='+',
help="Node.js source code directory/directories to scan",
required=False)
parser.add_argument("-o", "--output",
help="Output file to save JSON report",
required=False)
parser.add_argument("-v", "--version",
help="Show nodejsscan version",
required=False,
action='store_true')
args = parser.parse_args()
if args.directory:
scan_results = scan_dirs(args.directory)
output(args.output, scan_results)
elif args.file:
scan_results = scan_file(args.file)
output(args.output, scan_results)
elif args.version:
print("nodejsscan v" + settings.VERSION)
else:
parser.print_help()
if __name__ == "__main__":
main()