88namespace Magento \CloudPatches \Command \Process ;
99
1010use Magento \CloudPatches \Command \Process \Action \ReviewAppliedAction ;
11+ use Magento \CloudPatches \Composer \MagentoVersion ;
1112use Magento \CloudPatches \Console \QuestionFactory ;
1213use Magento \CloudPatches \Patch \Data \AggregatedPatch ;
1314use Magento \CloudPatches \Patch \Data \AggregatedPatchInterface ;
@@ -28,6 +29,8 @@ class ShowStatus implements ProcessInterface
2829
2930 const FILTER_OPTION_ALL = 'All ' ;
3031
32+ const FORMAT_JSON = 'json ' ;
33+
3134 /**
3235 * @var Aggregator
3336 */
@@ -43,6 +46,11 @@ class ShowStatus implements ProcessInterface
4346 */
4447 private $ localPool ;
4548
49+ /**
50+ * @var MagentoVersion
51+ */
52+ private $ magentoVersion ;
53+
4654 /**
4755 * @var StatusPool
4856 */
@@ -86,7 +94,8 @@ public function __construct(
8694 ReviewAppliedAction $ reviewAppliedAction ,
8795 Renderer $ renderer ,
8896 QuestionHelper $ questionHelper ,
89- QuestionFactory $ questionFactory
97+ QuestionFactory $ questionFactory ,
98+ MagentoVersion $ magentoVersion
9099 ) {
91100 $ this ->aggregator = $ aggregator ;
92101 $ this ->optionalPool = $ optionalPool ;
@@ -96,35 +105,44 @@ public function __construct(
96105 $ this ->renderer = $ renderer ;
97106 $ this ->questionHelper = $ questionHelper ;
98107 $ this ->questionFactory = $ questionFactory ;
108+ $ this ->magentoVersion = $ magentoVersion ;
99109 }
100110
101111 /**
102112 * @inheritDoc
103113 */
104114 public function run (InputInterface $ input , OutputInterface $ output )
105115 {
106- $ this ->printDetailsInfo ($ output );
107-
108- $ this ->reviewAppliedAction ->execute ($ input , $ output , []);
109-
116+ $ isJsonFormat = $ input ->getOption ('format ' ) === self ::FORMAT_JSON ;
110117 $ patches = $ this ->aggregator ->aggregate (
111118 array_merge ($ this ->optionalPool ->getList (), $ this ->localPool ->getList ())
112119 );
113- foreach ($ patches as $ patch ) {
114- if ($ patch ->isDeprecated () && $ this ->isPatchVisible ($ patch )) {
115- $ this ->printDeprecatedWarning ($ output , $ patch );
120+
121+ if (!$ isJsonFormat ) {
122+ $ this ->printDetailsInfo ($ output );
123+ $ this ->reviewAppliedAction ->execute ($ input , $ output , []);
124+ foreach ($ patches as $ patch ) {
125+ if ($ patch ->isDeprecated () && $ this ->isPatchVisible ($ patch )) {
126+ $ this ->printDeprecatedWarning ($ output , $ patch );
127+ }
116128 }
117129 }
130+
118131 $ patches = $ this ->filterNotVisiblePatches ($ patches );
119132
120- if (count ($ patches ) > self ::INTERACTIVE_FILTER_THRESHOLD ) {
133+ if (! $ isJsonFormat && count ($ patches ) > self ::INTERACTIVE_FILTER_THRESHOLD ) {
121134 $ this ->printPatchProviders ($ output , $ patches );
122135 $ patches = $ this ->filterByPatchProvider ($ input , $ output , $ patches );
123136 $ this ->printCategoriesInfo ($ output , $ patches );
124137 $ patches = $ this ->filterByPatchCategory ($ input , $ output , $ patches );
125138 }
126139
127- $ this ->renderer ->printTable ($ output , array_values ($ patches ));
140+ if ($ isJsonFormat ) {
141+ $ this ->renderer ->printJson ($ output , array_values ($ patches ));
142+ } else {
143+ $ this ->renderer ->printTable ($ output , array_values ($ patches ));
144+ $ output ->writeln ('<info> ' . $ this ->magentoVersion ->get () . '</info> ' );
145+ }
128146 }
129147
130148 /**
0 commit comments