33# Copyright (c) 2022 LG Electronics Inc.
44# SPDX-License-Identifier: Apache-2.0
55import sys
6+ import json
67from argparse import ArgumentParser
78from ._help import print_help_msg
89from .fosslight_scanner import run_main , PKG_NAME
10+ from ._parse_setting import parse_setting_json
911from fosslight_util .help import print_package_version
1012
1113
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+
1245def main ():
1346 parser = ArgumentParser (description = 'FOSSLight Scanner' , prog = 'fosslight_scanner' , add_help = False )
1447 parser .add_argument ('mode' , nargs = '*' , help = 'source| dependency| binary| all| compare' , default = "" )
@@ -26,6 +59,7 @@ def main():
2659 parser .add_argument ('--version' , '-v' , help = 'Print version' , action = 'store_true' , dest = 'version' , default = False )
2760 parser .add_argument ('--help' , '-h' , help = 'Print help message' , action = 'store_true' , dest = 'help' )
2861 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 = "" )
2963 parser .add_argument ('--no_correction' , help = 'No correction with sbom-info.yaml' ,
3064 action = 'store_true' , required = False , default = False )
3165 parser .add_argument ('--correct_fpath' , help = 'Path to the sbom-info.yaml' ,
@@ -35,18 +69,20 @@ def main():
3569 try :
3670 args = parser .parse_args ()
3771 except SystemExit :
38- sys .exit (0 )
72+ sys .exit (1 )
3973
4074 if args .help :
4175 print_help_msg ()
4276 elif args .version :
4377 print_package_version (PKG_NAME , "FOSSLight Scanner Version:" )
4478 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 )
5086
5187
5288if __name__ == "__main__" :
0 commit comments