def main(): """Main CLI.""" parser = argparse.ArgumentParser() parser.add_argument('path', nargs='*', help=('Path can be file(s) or ' 'directories with source code')) parser.add_argument('--json', help='set output format as JSON', action='store_true') parser.add_argument('--sarif', help='set output format as SARIF 2.1.0', action='store_true') parser.add_argument('--sonarqube', help='set output format compatible with SonarQube', action='store_true') parser.add_argument('-o', '--output', help='output filename to save the result', required=False) parser.add_argument('--missing-controls', help='enable missing security controls check', action='store_true', required=False) parser.add_argument('-w', '--exit-warning', help='non zero exit code on warning', action='store_true', required=False) parser.add_argument('-v', '--version', help='show njsscan version', required=False, action='store_true') args = parser.parse_args() if args.path: is_json = args.json or args.sonarqube or args.sarif scan_results = NJSScan( args.path, is_json, args.missing_controls, ).scan() if args.sonarqube: sonarqube.sonarqube_output(args.output, scan_results) elif args.json: json.json_output(args.output, scan_results) elif args.sarif: sarif.sarif_output(args.output, scan_results, __version__) else: cli.cli_output(args.output, scan_results) handle_exit(scan_results, args.exit_warning) elif args.version: print('njsscan: v' + __version__) else: parser.print_help()
def sarif_output(res): sarif_out = sarif.sarif_output(None, res, '0.0.0') assert sarif_out is not None