44
55use Composer \Command \BaseCommand ;
66use IonBazan \ComposerDiff \Formatter \Formatter ;
7+ use IonBazan \ComposerDiff \Formatter \JsonFormatter ;
78use IonBazan \ComposerDiff \Formatter \MarkdownListFormatter ;
89use IonBazan \ComposerDiff \Formatter \MarkdownTableFormatter ;
910use IonBazan \ComposerDiff \PackageDiff ;
@@ -48,7 +49,7 @@ protected function configure()
4849 ->addOption ('no-prod ' , null , InputOption::VALUE_NONE , 'Ignore prod dependencies ' )
4950 ->addOption ('with-platform ' , 'p ' , InputOption::VALUE_NONE , 'Include platform dependencies (PHP version, extensions, etc.) ' )
5051 ->addOption ('with-links ' , 'l ' , InputOption::VALUE_NONE , 'Include compare/release URLs ' )
51- ->addOption ('format ' , 'f ' , InputOption::VALUE_REQUIRED , 'Output format (mdtable, mdlist) ' , 'mdtable ' )
52+ ->addOption ('format ' , 'f ' , InputOption::VALUE_REQUIRED , 'Output format (mdtable, mdlist, json ) ' , 'mdtable ' )
5253 ->addOption ('gitlab-domains ' , null , InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY , 'Gitlab domains ' , array ())
5354 ;
5455 }
@@ -66,16 +67,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
6667
6768 $ formatter = $ this ->getFormatter ($ input , $ output );
6869
70+ $ prodOperations = array ();
71+ $ devOperations = array ();
72+
6973 if (!$ input ->getOption ('no-prod ' )) {
70- $ operations = $ this ->packageDiff ->getPackageDiff ($ base , $ target , false , $ withPlatform );
71- $ formatter ->render ($ operations , 'Prod Packages ' , $ withUrls );
74+ $ prodOperations = $ this ->packageDiff ->getPackageDiff ($ base , $ target , false , $ withPlatform );
7275 }
7376
7477 if (!$ input ->getOption ('no-dev ' )) {
75- $ operations = $ this ->packageDiff ->getPackageDiff ($ base , $ target , true , $ withPlatform );
76- $ formatter ->render ($ operations , 'Dev Packages ' , $ withUrls );
78+ $ devOperations = $ this ->packageDiff ->getPackageDiff ($ base , $ target , true , $ withPlatform );
7779 }
7880
81+ $ formatter ->render ($ prodOperations , $ devOperations , $ withUrls );
82+
7983 return 0 ;
8084 }
8185
@@ -87,6 +91,8 @@ private function getFormatter(InputInterface $input, OutputInterface $output)
8791 $ urlGenerators = new GeneratorContainer ($ this ->gitlabDomains );
8892
8993 switch ($ input ->getOption ('format ' )) {
94+ case 'json ' :
95+ return new JsonFormatter ($ output , $ urlGenerators );
9096 case 'mdlist ' :
9197 return new MarkdownListFormatter ($ output , $ urlGenerators );
9298 // case 'mdtable':
0 commit comments