Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
17 changes: 16 additions & 1 deletion src/Commands/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()) {
Expand Down Expand Up @@ -236,6 +247,10 @@ protected function arguments(): array
$arguments['--no-dev'] = true;
}

if ($this->latest) {
$arguments['--latest'] = true;
}

$arguments['--format'] = 'json';

return $arguments;
Expand Down
Loading