fix(commands): surface core fetch errors, run post-install in the project, exit 1 on invalid project command; document compat flow
This commit is contained in:
@@ -28,7 +28,8 @@ if ($command === null || in_array($command, $toolboxCommands, true)) {
|
||||
$coreCommand = 'Commands\\' . ucfirst($command);
|
||||
|
||||
if (!class_exists($coreCommand) && !file_exists(ROOT_CORE . '/Commands/' . ucfirst($command) . '.php')) {
|
||||
exit("Invalid command.\n");
|
||||
fwrite(STDERR, "Invalid command.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$cli = new $coreCommand();
|
||||
@@ -36,5 +37,6 @@ $cli = new $coreCommand();
|
||||
if ($cli instanceof Interfaces\CommandInterface) {
|
||||
call_user_func_array([$cli, 'run'], array_slice($argv, 2));
|
||||
} else {
|
||||
exit("Invalid command.\n");
|
||||
fwrite(STDERR, "La clase $coreCommand no implementa CommandInterface.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,35 @@
|
||||
{
|
||||
"name": "commands",
|
||||
"version": "0.2.0",
|
||||
"description": "CLI y migraciones para Duckbrain",
|
||||
"components": {
|
||||
"cli": {
|
||||
"files": [
|
||||
"duckbrain",
|
||||
"src/Interfaces/CommandInterface.php"
|
||||
]
|
||||
},
|
||||
"migration": {
|
||||
"files": [
|
||||
"src/Commands/Migration.php",
|
||||
"src/Libs/Migration.php"
|
||||
],
|
||||
"require": {
|
||||
"commands:cli": "*"
|
||||
}
|
||||
},
|
||||
"toolbox": {
|
||||
"files": [
|
||||
"src/Toolbox"
|
||||
]
|
||||
}
|
||||
"name": "commands",
|
||||
"version": "0.2.0",
|
||||
"description": "CLI y migraciones para Duckbrain",
|
||||
"components": {
|
||||
"cli": {
|
||||
"files": [
|
||||
"duckbrain",
|
||||
"src/Interfaces/CommandInterface.php"
|
||||
]
|
||||
},
|
||||
"default": [
|
||||
"cli",
|
||||
"migration"
|
||||
]
|
||||
"migration": {
|
||||
"files": [
|
||||
"src/Commands/Migration.php",
|
||||
"src/Libs/Migration.php"
|
||||
],
|
||||
"require": {
|
||||
"commands:cli": "*"
|
||||
},
|
||||
"core": {
|
||||
"requires": ">=0.1",
|
||||
"tested": "0.1"
|
||||
}
|
||||
},
|
||||
"toolbox": {
|
||||
"files": [
|
||||
"src/Toolbox"
|
||||
]
|
||||
}
|
||||
},
|
||||
"default": [
|
||||
"cli",
|
||||
"migration"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -36,7 +36,12 @@ final class CoreProvider
|
||||
throw new ToolboxException('No se pudo clonar el core: ' . implode("\n", $out));
|
||||
}
|
||||
} else {
|
||||
exec('git -C ' . escapeshellarg($dir) . ' fetch -q --tags 2>&1');
|
||||
exec('git -C ' . escapeshellarg($dir) . ' remote set-url origin ' . escapeshellarg($url) . ' 2>&1');
|
||||
$out = [];
|
||||
exec('git -C ' . escapeshellarg($dir) . ' fetch -q --tags 2>&1', $out, $code);
|
||||
if ($code !== 0) {
|
||||
throw new ToolboxException('No se pudo actualizar el core: ' . implode("\n", $out));
|
||||
}
|
||||
}
|
||||
|
||||
$provider = new self($dir);
|
||||
|
||||
@@ -191,7 +191,8 @@ final class Installer
|
||||
$manifest->postInstall,
|
||||
$this->console,
|
||||
(bool) ($options['yes'] ?? false),
|
||||
$options['postRunner'] ?? null
|
||||
$options['postRunner'] ?? null,
|
||||
$this->root,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,35 +11,51 @@ final class PostInstall
|
||||
/**
|
||||
* @param list<string> $commands
|
||||
* @param callable(string):int|null $runner
|
||||
* @param string|null $cwd Directorio de trabajo del proyecto: los
|
||||
* comandos se ejecutan alli, no donde arranco
|
||||
* el instalador.
|
||||
* @return list<string> comandos ejecutados
|
||||
*/
|
||||
public static function run(
|
||||
array $commands,
|
||||
Console $console,
|
||||
bool $assumeYes = false,
|
||||
?callable $runner = null
|
||||
?callable $runner = null,
|
||||
?string $cwd = null
|
||||
): array {
|
||||
$executed = [];
|
||||
$previous = null;
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$console->out(' post-install: ' . $command);
|
||||
if ($cwd !== null && is_dir($cwd)) {
|
||||
$previous = getcwd();
|
||||
chdir($cwd);
|
||||
}
|
||||
|
||||
if (!$console->confirm(' ¿Ejecutar?', $assumeYes)) {
|
||||
$console->warn('post-install omitido: ' . $command);
|
||||
try {
|
||||
foreach ($commands as $command) {
|
||||
$console->out(' post-install: ' . $command);
|
||||
|
||||
continue;
|
||||
}
|
||||
if (!$console->confirm(' ¿Ejecutar?', $assumeYes)) {
|
||||
$console->warn('post-install omitido: ' . $command);
|
||||
|
||||
if ($runner !== null) {
|
||||
$runner($command);
|
||||
} else {
|
||||
passthru($command, $code);
|
||||
if (($code ?? 0) !== 0) {
|
||||
throw new ToolboxException("post-install falló: {$command}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$executed[] = $command;
|
||||
if ($runner !== null) {
|
||||
$runner($command);
|
||||
} else {
|
||||
passthru($command, $code);
|
||||
if (($code ?? 0) !== 0) {
|
||||
throw new ToolboxException("post-install falló: {$command}");
|
||||
}
|
||||
}
|
||||
|
||||
$executed[] = $command;
|
||||
}
|
||||
} finally {
|
||||
if ($previous !== null) {
|
||||
chdir($previous);
|
||||
}
|
||||
}
|
||||
|
||||
return $executed;
|
||||
|
||||
Reference in New Issue
Block a user