1111use FancyGuy \Composer \SecurityCheck \Formatter \JsonFormatter ;
1212use FancyGuy \Composer \SecurityCheck \Formatter \SimpleFormatter ;
1313use FancyGuy \Composer \SecurityCheck \Formatter \TextFormatter ;
14+ use FancyGuy \Composer \SecurityCheck \Output \FileOutput ;
1415use Symfony \Component \Console \Input \InputOption ;
1516use Symfony \Component \Console \Input \InputInterface ;
1617use Symfony \Component \Console \Output \OutputInterface ;
@@ -26,6 +27,7 @@ protected function configure()
2627 ->setDefinition (array (
2728 new InputOption ('audit-db ' , '' , InputOption::VALUE_REQUIRED , 'Path to the advisory database ' ),
2829 new InputOption ('format ' , '' , InputOption::VALUE_REQUIRED , 'Output format ' , 'text ' ),
30+ new InputOption ('output-file ' , '' , InputOption::VALUE_REQUIRED , 'File to append the report output to ' ),
2931 new InputOption ('endpoint ' , '' , InputOption::VALUE_REQUIRED , 'Security checker server URL ' , HttpCheckerInterface::DEFAULT_ENDPOINT ),
3032 new InputOption ('timeout ' , '' , InputOption::VALUE_REQUIRED , 'HTTP timeout in seconds ' , HttpCheckerInterface::DEFAULT_TIMEOUT ),
3133 new InputOption ('file ' , '' , InputOption::VALUE_REQUIRED , 'Path to composer.lock file ' , './composer.lock ' ),
@@ -87,7 +89,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
8789 return 127 ;
8890 }
8991
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+
91103
92104 if ($ checker ->getLastVulnerabilityCount () > 0 ) {
93105 return 1 ;
0 commit comments