Files
duckbrain-toolbox/packages/commands/src/Toolbox/Commands/ListCommand.php
T

49 lines
1.3 KiB
PHP

<?php
namespace Toolbox\Commands;
use Toolbox\Installer;
use Toolbox\ToolboxException;
final class ListCommand extends Command
{
public static function describe(): string
{
return 'Lista el core y los componentes instalados';
}
public function run(array $args): int
{
$parsed = $this->parse($args);
$root = $this->root($parsed['options']);
$toolbox = $this->toolboxDir($parsed['options']);
$installer = new Installer($root, $toolbox, $this->console, $this->rootCore($parsed['options'], $root));
$rows = [['TIPO', 'ID', 'VERSIÓN', 'MODO', 'DESCRIPCIÓN']];
$core = $installer->lock()->core();
if ($core !== null) {
$rows[] = ['core', 'core', (string) ($core['version'] ?? '?'), 'copy', ''];
}
foreach ($installer->lock()->components() as $id => $entry) {
$rows[] = [
$entry['package'],
$id,
$entry['version'],
$entry['mode'],
$entry['description'] ?? '—',
];
}
if (count($rows) === 1) {
$this->console->out('No hay nada instalado.');
return 0;
}
$this->console->table($rows);
return 0;
}
}