3
3
# Copyright (c) 2022 LG Electronics Inc.
4
4
# SPDX-License-Identifier: Apache-2.0
5
5
import sys
6
+ import json
6
7
from argparse import ArgumentParser
7
8
from ._help import print_help_msg
8
9
from .fosslight_scanner import run_main , PKG_NAME
10
+ from ._parse_setting import parse_setting_json
9
11
from fosslight_util .help import print_package_version
10
12
11
13
14
+ def set_args (mode , path , dep_argument , output , format , link , db_url , timer ,
15
+ raw , core , no_correction , correct_fpath , ui , setting , exclude_path ):
16
+ if (setting ):
17
+ try :
18
+ with open (setting , 'r' , encoding = 'utf-8' ) as file :
19
+ data = json .load (file )
20
+ s_mode , s_path , s_dep_argument , s_output , s_format , s_link , s_db_url , s_timer , s_raw , s_core , \
21
+ s_no_correction , s_correct_fpath , s_ui , s_exclude_path = parse_setting_json (data )
22
+
23
+ # direct cli arguments have higher priority than setting file
24
+ mode = mode if mode else s_mode
25
+ path = path if path else s_path
26
+ dep_argument = dep_argument if dep_argument else s_dep_argument
27
+ output = output if output else s_output
28
+ format = format if format else s_format
29
+ link = link if link else s_link
30
+ db_url = db_url if db_url else s_db_url
31
+ timer = timer if timer else s_timer
32
+ raw = raw if raw else s_raw
33
+ core = core if core else s_core
34
+ no_correction = no_correction if no_correction else s_no_correction
35
+ correct_fpath = correct_fpath if correct_fpath else s_correct_fpath
36
+ ui = ui if ui else s_ui
37
+ exclude_path = exclude_path if exclude_path else s_exclude_path
38
+
39
+ except Exception as e :
40
+ print (f"Cannot open setting file: { e } " )
41
+ return mode , path , dep_argument , output , format , link , db_url , timer , \
42
+ raw , core , no_correction , correct_fpath , ui , exclude_path
43
+
44
+
12
45
def main ():
13
46
parser = ArgumentParser (description = 'FOSSLight Scanner' , prog = 'fosslight_scanner' , add_help = False )
14
47
parser .add_argument ('mode' , nargs = '*' , help = 'source| dependency| binary| all| compare' , default = "" )
@@ -26,6 +59,7 @@ def main():
26
59
parser .add_argument ('--version' , '-v' , help = 'Print version' , action = 'store_true' , dest = 'version' , default = False )
27
60
parser .add_argument ('--help' , '-h' , help = 'Print help message' , action = 'store_true' , dest = 'help' )
28
61
parser .add_argument ('--exclude' , '-e' , help = 'Path to exclude from analysis' , dest = 'exclude_path' , nargs = '*' , default = [])
62
+ parser .add_argument ('--setting' , '-s' , help = 'Scanner json setting file' , type = str , dest = 'setting' , default = "" )
29
63
parser .add_argument ('--no_correction' , help = 'No correction with sbom-info.yaml' ,
30
64
action = 'store_true' , required = False , default = False )
31
65
parser .add_argument ('--correct_fpath' , help = 'Path to the sbom-info.yaml' ,
@@ -35,18 +69,20 @@ def main():
35
69
try :
36
70
args = parser .parse_args ()
37
71
except SystemExit :
38
- sys .exit (0 )
72
+ sys .exit (1 )
39
73
40
74
if args .help :
41
75
print_help_msg ()
42
76
elif args .version :
43
77
print_package_version (PKG_NAME , "FOSSLight Scanner Version:" )
44
78
else :
45
- if not args .mode :
46
- args .mode = ['all' ]
47
- run_main (args .mode , args .path , args .dep_argument , args .output , args .format ,
48
- args .link , args .db_url , args .timer , args .raw , args .core ,
49
- not args .no_correction , args .correct_fpath , args .ui , args .exclude_path )
79
+ mode , path , dep_argument , output , format , link , db_url , timer , raw , core , no_correction , correct_fpath , \
80
+ ui , exclude_path = set_args (args .mode , args .path , args .dep_argument , args .output , args .format ,
81
+ args .link , args .db_url , args .timer , args .raw , args .core , args .no_correction ,
82
+ args .correct_fpath , args .ui , args .setting , args .exclude_path )
83
+
84
+ run_main (mode , path , dep_argument , output , format , link , db_url , timer ,
85
+ raw , core , not no_correction , correct_fpath , ui , exclude_path )
50
86
51
87
52
88
if __name__ == "__main__" :
0 commit comments