11
11
use FancyGuy \Composer \SecurityCheck \Formatter \JsonFormatter ;
12
12
use FancyGuy \Composer \SecurityCheck \Formatter \SimpleFormatter ;
13
13
use FancyGuy \Composer \SecurityCheck \Formatter \TextFormatter ;
14
+ use FancyGuy \Composer \SecurityCheck \Output \FileOutput ;
14
15
use Symfony \Component \Console \Input \InputOption ;
15
16
use Symfony \Component \Console \Input \InputInterface ;
16
17
use Symfony \Component \Console \Output \OutputInterface ;
@@ -26,6 +27,7 @@ protected function configure()
26
27
->setDefinition (array (
27
28
new InputOption ('audit-db ' , '' , InputOption::VALUE_REQUIRED , 'Path to the advisory database ' ),
28
29
new InputOption ('format ' , '' , InputOption::VALUE_REQUIRED , 'Output format ' , 'text ' ),
30
+ new InputOption ('output-file ' , '' , InputOption::VALUE_REQUIRED , 'File to append the report output to ' ),
29
31
new InputOption ('endpoint ' , '' , InputOption::VALUE_REQUIRED , 'Security checker server URL ' , HttpCheckerInterface::DEFAULT_ENDPOINT ),
30
32
new InputOption ('timeout ' , '' , InputOption::VALUE_REQUIRED , 'HTTP timeout in seconds ' , HttpCheckerInterface::DEFAULT_TIMEOUT ),
31
33
new InputOption ('file ' , '' , InputOption::VALUE_REQUIRED , 'Path to composer.lock file ' , './composer.lock ' ),
@@ -87,7 +89,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
87
89
return 127 ;
88
90
}
89
91
90
- $ formatter ->displayResults ($ output , $ composerFile , $ vulnerabilities );
92
+ if ($ outputFile = $ input ->getOption ('output-file ' )) {
93
+ $ formatter ->displayResults (
94
+ new FileOutput ($ outputFile , $ output ->getVerbosity (), $ output ->isDecorated (), $ output ->getFormatter ()),
95
+ $ composerFile ,
96
+ $ vulnerabilities
97
+ );
98
+ $ output ->writeln (sprintf ('Report written to: %s ' , $ outputFile ));
99
+ } else {
100
+ $ formatter ->displayResults ($ output , $ composerFile , $ vulnerabilities );
101
+ }
102
+
91
103
92
104
if ($ checker ->getLastVulnerabilityCount () > 0 ) {
93
105
return 1 ;
0 commit comments