@@ -24,13 +24,17 @@ class Show extends BaseCommand
2424 * @param ShowMode $mode Mode to run the command against
2525 * @param string|null $package Individual package to search
2626 * @param boolean $noDev Exclude dev dependencies from search
27+ * @param boolean $latest Include the latest key (might only be present when returnArray = true)
28+ * @param boolean $returnArray Return the results as an array.
2729 * @return void
2830 */
2931 final public function __construct (
3032 Composer $ composer ,
3133 public ShowMode $ mode = ShowMode::INSTALLED ,
3234 public ?string $ package = null ,
33- public bool $ noDev = false
35+ public bool $ noDev = false ,
36+ public bool $ latest = false ,
37+ public bool $ returnArray = false ,
3438 ) {
3539 parent ::__construct ($ composer );
3640 }
@@ -56,6 +60,13 @@ public function execute()
5660 }
5761
5862 $ results = json_decode (implode (PHP_EOL , $ output ['output ' ]), true );
63+
64+ if ($ this ->returnArray ) {
65+ return $ this ->package
66+ ? $ results ?? []
67+ : $ results ['installed ' ] ?? [];
68+ }
69+
5970 $ packages = [];
6071
6172 if (is_null ($ this ->package ) && $ this ->mode ->isCollectible ()) {
@@ -236,6 +247,10 @@ protected function arguments(): array
236247 $ arguments ['--no-dev ' ] = true ;
237248 }
238249
250+ if ($ this ->latest ) {
251+ $ arguments ['--latest ' ] = true ;
252+ }
253+
239254 $ arguments ['--format ' ] = 'json ' ;
240255
241256 return $ arguments ;
0 commit comments