77use IonBazan \ComposerDiff \Formatter \MarkdownListFormatter ;
88use IonBazan \ComposerDiff \Formatter \MarkdownTableFormatter ;
99use IonBazan \ComposerDiff \PackageDiff ;
10+ use IonBazan \ComposerDiff \Url \GeneratorContainer ;
1011use Symfony \Component \Console \Input \InputInterface ;
1112use Symfony \Component \Console \Input \InputOption ;
1213use Symfony \Component \Console \Output \OutputInterface ;
@@ -18,13 +19,25 @@ class DiffCommand extends BaseCommand
1819 */
1920 protected $ packageDiff ;
2021
21- public function __construct (PackageDiff $ packageDiff )
22+ /**
23+ * @var string[]
24+ */
25+ protected $ gitlabDomains ;
26+
27+ /**
28+ * @param string[] $gitlabDomains
29+ */
30+ public function __construct (PackageDiff $ packageDiff , array $ gitlabDomains = array ())
2231 {
2332 $ this ->packageDiff = $ packageDiff ;
33+ $ this ->gitlabDomains = $ gitlabDomains ;
2434
2535 parent ::__construct ();
2636 }
2737
38+ /**
39+ * @return void
40+ */
2841 protected function configure ()
2942 {
3043 $ this ->setName ('diff ' )
@@ -34,25 +47,33 @@ protected function configure()
3447 ->addOption ('no-dev ' , null , InputOption::VALUE_NONE , 'Ignore dev dependencies ' )
3548 ->addOption ('no-prod ' , null , InputOption::VALUE_NONE , 'Ignore prod dependencies ' )
3649 ->addOption ('with-platform ' , 'p ' , InputOption::VALUE_NONE , 'Include platform dependencies (PHP version, extensions, etc.) ' )
50+ ->addOption ('with-links ' , 'l ' , InputOption::VALUE_NONE , 'Include compare/release URLs ' )
3751 ->addOption ('format ' , 'f ' , InputOption::VALUE_REQUIRED , 'Output format (mdtable, mdlist) ' , 'mdtable ' )
52+ ->addOption ('gitlab-domains ' , null , InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY , 'Gitlab domains ' , array ())
3853 ;
3954 }
4055
56+ /**
57+ * {@inheritdoc}
58+ */
4159 protected function execute (InputInterface $ input , OutputInterface $ output )
4260 {
4361 $ base = $ input ->getOption ('base ' );
4462 $ target = $ input ->getOption ('target ' );
4563 $ withPlatform = $ input ->getOption ('with-platform ' );
64+ $ withUrls = $ input ->getOption ('with-links ' );
65+ $ this ->gitlabDomains = array_merge ($ this ->gitlabDomains , $ input ->getOption ('gitlab-domains ' ));
66+
4667 $ formatter = $ this ->getFormatter ($ input , $ output );
4768
4869 if (!$ input ->getOption ('no-prod ' )) {
4970 $ operations = $ this ->packageDiff ->getPackageDiff ($ base , $ target , false , $ withPlatform );
50- $ formatter ->render ($ operations , 'Prod Packages ' , $ output );
71+ $ formatter ->render ($ operations , 'Prod Packages ' , $ withUrls );
5172 }
5273
5374 if (!$ input ->getOption ('no-dev ' )) {
5475 $ operations = $ this ->packageDiff ->getPackageDiff ($ base , $ target , true , $ withPlatform );
55- $ formatter ->render ($ operations , 'Dev Packages ' , $ output );
76+ $ formatter ->render ($ operations , 'Dev Packages ' , $ withUrls );
5677 }
5778
5879 return 0 ;
@@ -63,12 +84,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
6384 */
6485 private function getFormatter (InputInterface $ input , OutputInterface $ output )
6586 {
87+ $ urlGenerators = new GeneratorContainer ($ this ->gitlabDomains );
88+
6689 switch ($ input ->getOption ('format ' )) {
6790 case 'mdlist ' :
68- return new MarkdownListFormatter ($ output );
91+ return new MarkdownListFormatter ($ output, $ urlGenerators );
6992 case 'mdtable ' :
7093 default :
71- return new MarkdownTableFormatter ($ output );
94+ return new MarkdownTableFormatter ($ output, $ urlGenerators );
7295 }
7396 }
7497}
0 commit comments