diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php index 8ed8494..2faafc5 100644 --- a/src/Commands/BaseCommand.php +++ b/src/Commands/BaseCommand.php @@ -168,12 +168,14 @@ protected function runComposerCommand(): array $return = [ 'code' => $code, 'output' => preg_split('/(\n|\r\n)/', trim($output->fetch())), + 'arguments' => $arguments, ]; } catch (\Exception $e) { $return = [ 'code' => 1, 'output' => preg_split('/(\n|\r\n)/', $e->getMessage()), 'exception' => $e, + 'arguments' => $arguments, ]; } diff --git a/src/Commands/Show.php b/src/Commands/Show.php index 562a983..8c3c664 100644 --- a/src/Commands/Show.php +++ b/src/Commands/Show.php @@ -24,13 +24,17 @@ class Show extends BaseCommand * @param ShowMode $mode Mode to run the command against * @param string|null $package Individual package to search * @param boolean $noDev Exclude dev dependencies from search + * @param boolean $latest Include the latest key (might only be present when returnArray = true) + * @param boolean $returnArray Return the results as an array. * @return void */ final public function __construct( Composer $composer, public ShowMode $mode = ShowMode::INSTALLED, public ?string $package = null, - public bool $noDev = false + public bool $noDev = false, + public bool $latest = false, + public bool $returnArray = false, ) { parent::__construct($composer); } @@ -56,6 +60,13 @@ public function execute() } $results = json_decode(implode(PHP_EOL, $output['output']), true); + + if ($this->returnArray) { + return $this->package + ? $results ?? [] + : $results['installed'] ?? []; + } + $packages = []; if (is_null($this->package) && $this->mode->isCollectible()) { @@ -236,6 +247,10 @@ protected function arguments(): array $arguments['--no-dev'] = true; } + if ($this->latest) { + $arguments['--latest'] = true; + } + $arguments['--format'] = 'json'; return $arguments;