@@ -26,29 +26,56 @@ def main(argv=None):
2626 log .set_debug_level (args .verbose )
2727
2828 if args .action == 'scan' :
29- output = json .dumps (
30- _perform_scan (args ),
31- indent = 2 ,
32- sort_keys = True ,
33- )
29+ # Plugins are *always* rescanned with fresh settings, because
30+ # we want to get the latest updates.
31+ plugins = initialize .from_parser_builder (args .plugins )
32+ if args .string :
33+ line = args .string
34+
35+ if isinstance (args .string , bool ):
36+ line = sys .stdin .read ().splitlines ()[0 ]
37+
38+ _scan_string (line , plugins )
3439
35- if args .import_filename :
36- _write_to_file (args .import_filename [0 ], output )
3740 else :
38- print (output )
41+ output = json .dumps (
42+ _perform_scan (args , plugins ),
43+ indent = 2 ,
44+ sort_keys = True ,
45+ )
46+
47+ if args .import_filename :
48+ _write_to_file (args .import_filename [0 ], output )
49+ else :
50+ print (output )
3951
4052 elif args .action == 'audit' :
4153 audit .audit_baseline (args .filename [0 ])
4254
4355 return 0
4456
4557
46- def _perform_scan (args ):
47- old_baseline = _get_existing_baseline (args .import_filename )
58+ def _scan_string (line , plugins ):
59+ longest_plugin_name_length = max (
60+ map (
61+ lambda x : len (x .__class__ .__name__ ),
62+ plugins ,
63+ ),
64+ )
4865
49- # Plugins are *always* rescanned with fresh settings, because
50- # we want to get the latest updates.
51- plugins = initialize .from_parser_builder (args .plugins )
66+ output = [
67+ ('{:%d}: {}' % longest_plugin_name_length ).format (
68+ plugin .__class__ .__name__ ,
69+ plugin .adhoc_scan (line ),
70+ )
71+ for plugin in plugins
72+ ]
73+
74+ print ('\n ' .join (sorted (output )))
75+
76+
77+ def _perform_scan (args , plugins ):
78+ old_baseline = _get_existing_baseline (args .import_filename )
5279
5380 # Favors --exclude argument over existing baseline's regex (if exists)
5481 if args .exclude :
0 commit comments