feat(cli): lock captures effective description; list shows it; new commands surface view with origin and collision reporting
This commit is contained in:
@@ -25,7 +25,7 @@ class Toolbox implements CommandInterface
|
||||
public static function aliases(): array
|
||||
{
|
||||
return [
|
||||
'add', 'remove', 'update', 'list', 'doctor', 'catalog', 'adopt',
|
||||
'add', 'remove', 'update', 'list', 'doctor', 'catalog', 'adopt', 'commands',
|
||||
'help', '--help', '-h', '--version', '-V',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Toolbox;
|
||||
use Toolbox\Commands\AddCommand;
|
||||
use Toolbox\Commands\AdoptCommand;
|
||||
use Toolbox\Commands\CatalogCommand;
|
||||
use Toolbox\Commands\CommandsCommand;
|
||||
use Toolbox\Commands\DoctorCommand;
|
||||
use Toolbox\Commands\InstallCommand;
|
||||
use Toolbox\Commands\ListCommand;
|
||||
@@ -24,6 +25,7 @@ final class Cli
|
||||
'doctor' => DoctorCommand::class,
|
||||
'catalog' => CatalogCommand::class,
|
||||
'adopt' => AdoptCommand::class,
|
||||
'commands' => CommandsCommand::class,
|
||||
'self-update' => SelfUpdateCommand::class,
|
||||
];
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ final class AdoptCommand extends Command
|
||||
'toolbox_commit' => null,
|
||||
'mode' => 'copy',
|
||||
'origin' => $hasLocal ? 'local' : 'adopted',
|
||||
'description' => $package->descriptionOf($component->name),
|
||||
'files' => $files,
|
||||
]);
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Toolbox\Commands;
|
||||
|
||||
use Toolbox\Lock;
|
||||
use Toolbox\Ownership;
|
||||
|
||||
/**
|
||||
* Superficie ejecutable del proyecto: comandos en src/Commands con sus
|
||||
* aliases, descripciones y origen. A diferencia del despachador del bin,
|
||||
* las colisiones de alias aquí se REPORTAN (marcadas con !) y no abortan.
|
||||
*/
|
||||
final class CommandsCommand extends Command
|
||||
{
|
||||
public static function describe(): string
|
||||
{
|
||||
return 'Lista los comandos disponibles del proyecto';
|
||||
}
|
||||
|
||||
public function run(array $args): int
|
||||
{
|
||||
$parsed = $this->parse($args);
|
||||
$root = $this->root($parsed['options']);
|
||||
|
||||
$autoload = $root . '/autoload.php';
|
||||
if (!defined('ROOT_CORE') && is_file($autoload)) {
|
||||
$previous = getcwd();
|
||||
chdir($root);
|
||||
try {
|
||||
include_once $autoload;
|
||||
} catch (\Throwable) {
|
||||
// el proyecto no arranca: se lista sin clases cargables
|
||||
}
|
||||
if ($previous !== false) {
|
||||
chdir($previous);
|
||||
}
|
||||
}
|
||||
|
||||
$coreDir = defined('ROOT_CORE') ? rtrim(ROOT_CORE, '/') : $root . '/src';
|
||||
$dir = $coreDir . '/Commands';
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
$this->console->out('El proyecto no tiene comandos en src/Commands.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$lock = Lock::load($root);
|
||||
$ownership = Ownership::fromLock($lock);
|
||||
|
||||
$info = [];
|
||||
$aliasOwners = [];
|
||||
|
||||
foreach (glob($dir . '/*.php') as $file) {
|
||||
$base = basename($file, '.php');
|
||||
$class = 'Commands\\' . $base;
|
||||
|
||||
if (!class_exists($class, true) || !is_a($class, 'Interfaces\\CommandInterface', true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$aliases = method_exists($class, 'aliases') ? $class::aliases() : [];
|
||||
foreach ($aliases as $alias) {
|
||||
$aliasOwners[strtolower((string) $alias)][] = $class;
|
||||
}
|
||||
|
||||
$owner = $ownership->ownerOf('src/Commands/' . $base . '.php');
|
||||
$origin = 'proyecto';
|
||||
if ($owner === 'core') {
|
||||
$origin = 'core';
|
||||
} elseif ($owner !== null) {
|
||||
$origin = $owner . '@' . ($lock->component($owner)['version'] ?? '?');
|
||||
}
|
||||
|
||||
$info[$base] = [
|
||||
'class' => $class,
|
||||
'describe' => $class::describe(),
|
||||
'aliases' => $aliases,
|
||||
'origin' => $origin,
|
||||
];
|
||||
}
|
||||
|
||||
$collisions = [];
|
||||
foreach ($aliasOwners as $alias => $owners) {
|
||||
$uniq = array_unique($owners);
|
||||
if (count($uniq) > 1) {
|
||||
$collisions[$alias] = $uniq;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($info as $base => $row) {
|
||||
foreach ($row['aliases'] as $alias) {
|
||||
$aKey = strtolower((string) $alias);
|
||||
foreach (array_keys($info) as $other) {
|
||||
if (strtolower($other) !== $aKey || $other === $base) {
|
||||
continue;
|
||||
}
|
||||
$owners = array_values(array_unique([...($collisions[$aKey] ?? []), $row['class'], $info[$other]['class']]));
|
||||
$collisions[$aKey] = $owners;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rows = [['COMANDO', 'ALIASES', 'DESCRIPCIÓN', 'ORIGEN']];
|
||||
foreach ($info as $base => $row) {
|
||||
$marks = [];
|
||||
foreach ($row['aliases'] as $alias) {
|
||||
$marks[] = (isset($collisions[strtolower((string) $alias)]) ? $alias . '!' : (string) $alias);
|
||||
}
|
||||
$marked = $marks === [] ? '—' : implode(', ', $marks);
|
||||
if ($marked !== '—' && isset($collisions[strtolower($base)])) {
|
||||
$marked .= ' !';
|
||||
}
|
||||
|
||||
$rows[] = [strtolower($base), $marked, $row['describe'], $row['origin']];
|
||||
}
|
||||
|
||||
$this->console->table($rows);
|
||||
|
||||
foreach ($collisions as $alias => $owners) {
|
||||
$this->console->warn("alias '{$alias}' declarado o robado por: " . implode(', ', $owners));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -19,15 +19,21 @@ final class ListCommand extends Command
|
||||
$toolbox = $this->toolboxDir($parsed['options']);
|
||||
$installer = new Installer($root, $toolbox, $this->console, $this->rootCore($parsed['options'], $root));
|
||||
|
||||
$rows = [['TIPO', 'ID', 'VERSIÓN', 'MODO']];
|
||||
$rows = [['TIPO', 'ID', 'VERSIÓN', 'MODO', 'DESCRIPCIÓN']];
|
||||
|
||||
$core = $installer->lock()->core();
|
||||
if ($core !== null) {
|
||||
$rows[] = ['core', 'core', (string) ($core['version'] ?? '?'), 'copy'];
|
||||
$rows[] = ['core', 'core', (string) ($core['version'] ?? '?'), 'copy', ''];
|
||||
}
|
||||
|
||||
foreach ($installer->lock()->components() as $id => $entry) {
|
||||
$rows[] = [$entry['package'], $id, $entry['version'], $entry['mode']];
|
||||
$rows[] = [
|
||||
$entry['package'],
|
||||
$id,
|
||||
$entry['version'],
|
||||
$entry['mode'],
|
||||
$entry['description'] ?? '—',
|
||||
];
|
||||
}
|
||||
|
||||
if (count($rows) === 1) {
|
||||
|
||||
@@ -157,6 +157,7 @@ final class Installer
|
||||
'version' => $version,
|
||||
'toolbox_commit' => $commit,
|
||||
'mode' => $mode,
|
||||
'description' => $manifest->descriptionOf($componentName),
|
||||
'files' => $result['files'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ final class Lock
|
||||
'toolbox_commit' => $entry['toolbox_commit'] ?? null,
|
||||
'mode' => (string) ($entry['mode'] ?? 'copy'),
|
||||
'origin' => (string) ($entry['origin'] ?? 'toolbox'),
|
||||
'description' => $entry['description'] ?? null,
|
||||
'files' => is_array($entry['files'] ?? null) ? $entry['files'] : [],
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user