2929use Symfony \Component \Console \Output \OutputInterface ;
3030use Symfony \Component \Console \Question \ConfirmationQuestion ;
3131use GuzzleHttp \Client ;
32+ use InvalidArgumentException ;
3233
3334/**
3435 * List repo details
@@ -49,6 +50,7 @@ protected function configure()
4950 ->addOption ('page ' , 'p ' , InputOption::VALUE_REQUIRED , 'page to start from ' , '1 ' )
5051 ->addOption ('results-per-page ' , 'r ' , InputOption::VALUE_REQUIRED , 'results to display per page (0 for all) ' , '10 ' )
5152 ->addOption ('new-packagist-token ' , '' , InputOption::VALUE_REQUIRED , 'update the packagist token ' )
53+ ->addOption ('format ' , 'f ' , InputOption::VALUE_REQUIRED , 'can be "ci" or "table" ' , 'table ' )
5254 ;
5355 }
5456
@@ -72,6 +74,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
7274 }
7375 $ page = (int ) $ input ->getOption ('page ' );
7476 $ resultsPerPage = (int ) $ input ->getOption ('results-per-page ' );
77+ $ format = $ input ->getOption ('format ' );
78+ if (!in_array ($ format , ['ci ' , 'table ' ])) {
79+ throw new InvalidArgumentException ('Invalid format " ' . $ format . '", must be "table" or "ci" ' );
80+ }
7581 $ components = $ componentName ? [new Component ($ componentName )] : Component::getComponents ();
7682
7783 if (!$ input ->getOption ('token ' )) {
@@ -81,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8187 if ($ i < (($ page -1 ) * $ resultsPerPage )) {
8288 continue ;
8389 }
84- if (0 !== $ resultsPerPage && $ i >= ($ page * $ resultsPerPage )) {
90+ if ($ format == ' table ' && 0 !== $ resultsPerPage && $ i >= ($ page * $ resultsPerPage )) {
8591 $ table ->render ();
8692 if (!$ this ->getHelper ('question ' )->ask ($ input , $ output , $ nextPageQuestion )) {
8793 return 0 ;
@@ -135,17 +141,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
135141 }
136142 }
137143
144+ if ($ format == 'ci ' ) {
145+ $ output ->writeln ($ component ->getName () . ': ' . $ details ['compliant ' ]);
146+ if (!$ isCompliant ) {
147+ return 1 ;
148+ }
149+ }
150+
138151 if (!$ isCompliant ) {
139152 $ details ['compliant ' ] .= PHP_EOL . implode ("\n" , array_map (
140153 fn ($ k , $ v ) => $ k . ': ' . (is_null ($ v ) ? '??? ' : var_export ($ v , true )),
141154 array_keys ($ compliance ),
142155 array_values ($ compliance )
143156 ));
144157 }
145-
146158 $ table ->addRow ($ details );
147159 }
148- $ table ->render ();
160+ if ($ format == 'table ' ) {
161+ $ table ->render ();
162+ }
149163
150164 return 0 ;
151165 }
0 commit comments