first commit.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Toolbox;
|
||||
|
||||
/**
|
||||
* Ejecuta los comandos `post-install` de un paquete, mostrándolos y pidiendo
|
||||
* confirmación salvo en modo `--yes`.
|
||||
*/
|
||||
final class PostInstall
|
||||
{
|
||||
/**
|
||||
* @param list<string> $commands
|
||||
* @param callable(string):int|null $runner
|
||||
* @return list<string> comandos ejecutados
|
||||
*/
|
||||
public static function run(
|
||||
array $commands,
|
||||
Console $console,
|
||||
bool $assumeYes = false,
|
||||
?callable $runner = null
|
||||
): array {
|
||||
$executed = [];
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$console->out(' post-install: ' . $command);
|
||||
|
||||
if (!$console->confirm(' ¿Ejecutar?', $assumeYes)) {
|
||||
$console->warn('post-install omitido: ' . $command);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($runner !== null) {
|
||||
$runner($command);
|
||||
} else {
|
||||
passthru($command, $code);
|
||||
if (($code ?? 0) !== 0) {
|
||||
throw new ToolboxException("post-install falló: {$command}");
|
||||
}
|
||||
}
|
||||
|
||||
$executed[] = $command;
|
||||
}
|
||||
|
||||
return $executed;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user