@@ -80,16 +80,24 @@ def _init_extensions():
80
80
return ext_loader .MANAGER
81
81
82
82
83
- def _log_option_source (arg_val , ini_val , option_name ):
83
+ def _log_option_source (default_val , arg_val , ini_val , option_name ):
84
84
"""It's useful to show the source of each option."""
85
- if arg_val :
86
- LOG .info ("Using command line arg for %s" , option_name )
87
- return arg_val
88
- elif ini_val :
89
- LOG .info ("Using ini file for %s" , option_name )
90
- return ini_val
85
+ # When default value is not defined, arg_val and ini_val is deterministic
86
+ if default_val is None :
87
+ if arg_val :
88
+ LOG .info ("Using command line arg for %s" , option_name )
89
+ return arg_val
90
+ elif ini_val :
91
+ LOG .info ("Using ini file for %s" , option_name )
92
+ return ini_val
93
+ else :
94
+ return None
95
+ # No value passed to commad line and default value is used
96
+ elif default_val == arg_val :
97
+ return ini_val if ini_val else arg_val
98
+ # Certainly a value is passed to commad line
91
99
else :
92
- return None
100
+ return arg_val
93
101
94
102
95
103
def _running_under_virtualenv ():
@@ -354,16 +362,19 @@ def main():
354
362
if ini_options :
355
363
# prefer command line, then ini file
356
364
args .excluded_paths = _log_option_source (
365
+ parser .get_default ('excluded_paths' ),
357
366
args .excluded_paths ,
358
367
ini_options .get ('exclude' ),
359
368
'excluded paths' )
360
369
361
370
args .skips = _log_option_source (
371
+ parser .get_default ('skips' ),
362
372
args .skips ,
363
373
ini_options .get ('skips' ),
364
374
'skipped tests' )
365
375
366
376
args .tests = _log_option_source (
377
+ parser .get_default ('tests' ),
367
378
args .tests ,
368
379
ini_options .get ('tests' ),
369
380
'selected tests' )
@@ -373,78 +384,93 @@ def main():
373
384
ini_targets = ini_targets .split (',' )
374
385
375
386
args .targets = _log_option_source (
387
+ parser .get_default ('targets' ),
376
388
args .targets ,
377
389
ini_targets ,
378
390
'selected targets' )
379
391
380
392
# TODO(tmcpeak): any other useful options to pass from .bandit?
381
393
382
394
args .recursive = _log_option_source (
395
+ parser .get_default ('recursive' ),
383
396
args .recursive ,
384
397
ini_options .get ('recursive' ),
385
398
'recursive scan' )
386
399
387
400
args .agg_type = _log_option_source (
401
+ parser .get_default ('agg_type' ),
388
402
args .agg_type ,
389
403
ini_options .get ('aggregate' ),
390
404
'aggregate output type' )
391
405
392
406
args .context_lines = _log_option_source (
407
+ parser .get_default ('context_lines' ),
393
408
args .context_lines ,
394
409
ini_options .get ('number' ),
395
410
'max code lines output for issue' )
396
411
397
412
args .profile = _log_option_source (
413
+ parser .get_default ('profile' ),
398
414
args .profile ,
399
415
ini_options .get ('profile' ),
400
416
'profile' )
401
417
402
418
args .severity = _log_option_source (
419
+ parser .get_default ('severity' ),
403
420
args .severity ,
404
421
ini_options .get ('level' ),
405
422
'severity level' )
406
423
407
424
args .confidence = _log_option_source (
425
+ parser .get_default ('confidence' ),
408
426
args .confidence ,
409
427
ini_options .get ('confidence' ),
410
428
'confidence level' )
411
429
412
430
args .output_format = _log_option_source (
431
+ parser .get_default ('output_format' ),
413
432
args .output_format ,
414
433
ini_options .get ('format' ),
415
434
'output format' )
416
435
417
436
args .msg_template = _log_option_source (
437
+ parser .get_default ('msg_template' ),
418
438
args .msg_template ,
419
439
ini_options .get ('msg-template' ),
420
440
'output message template' )
421
441
422
442
args .output_file = _log_option_source (
443
+ parser .get_default ('output_file' ),
423
444
args .output_file ,
424
445
ini_options .get ('output' ),
425
446
'output file' )
426
447
427
448
args .verbose = _log_option_source (
449
+ parser .get_default ('verbose' ),
428
450
args .verbose ,
429
451
ini_options .get ('verbose' ),
430
452
'output extra information' )
431
453
432
454
args .debug = _log_option_source (
455
+ parser .get_default ('debug' ),
433
456
args .debug ,
434
457
ini_options .get ('debug' ),
435
458
'debug mode' )
436
459
437
460
args .quiet = _log_option_source (
461
+ parser .get_default ('quiet' ),
438
462
args .quiet ,
439
463
ini_options .get ('quiet' ),
440
464
'silent mode' )
441
465
442
466
args .ignore_nosec = _log_option_source (
467
+ parser .get_default ('ignore_nosec' ),
443
468
args .ignore_nosec ,
444
469
ini_options .get ('ignore-nosec' ),
445
470
'do not skip lines with # nosec' )
446
471
447
472
args .baseline = _log_option_source (
473
+ parser .get_default ('baseline' ),
448
474
args .baseline ,
449
475
ini_options .get ('baseline' ),
450
476
'path of a baseline report' )
0 commit comments