Skip to content

Commit f10025e

Browse files
committed
fix: add runCommand method.
1 parent 1e292a7 commit f10025e

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/NewCommand.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
use Symfony\Component\Console\Input\InputOption;
1313
use Symfony\Component\Console\Output\OutputInterface;
1414
use Symfony\Component\Process\Exception\ProcessStartFailedException;
15+
use Symfony\Component\Console\Terminal;
1516
use Symfony\Component\Process\PhpExecutableFinder;
1617
use Symfony\Component\Process\Process;
17-
1818
use function Laravel\Prompts\confirm;
1919
use function Laravel\Prompts\multiselect;
2020
use function Laravel\Prompts\select;
@@ -892,13 +892,39 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
892892
}, $commands);
893893
}
894894

895-
$commands = implode(' && ', $commands);
895+
foreach ($commands as $command) {
896+
$process = $this->runCommand($command, $input, $output, $workingPath, $env);
896897

897-
if ($this->canUseSpinner($input, $output)) {
898-
$commands .= ' > /dev/null 2>&1';
898+
if (! $process->isSuccessful()) {
899+
$output->writeln(' <bg=red;fg=white> ERROR </> '.$process->getErrorOutput().PHP_EOL);
900+
901+
break;
902+
}
899903
}
900904

901-
$process = Process::fromShellCommandline($commands, $workingPath, $env, null, null);
905+
return $process;
906+
}
907+
908+
/**
909+
* Run the given command.
910+
*
911+
* @param string $command
912+
* @param InputInterface $input
913+
* @param OutputInterface $output
914+
* @param string|null $workingPath
915+
* @param array $env
916+
* @return \Symfony\Component\Process\Process
917+
*/
918+
protected function runCommand(string $command, InputInterface $input, OutputInterface $output, string $workingPath = null, array $env = [])
919+
{
920+
$process = Process::fromShellCommandline($command, $workingPath, $env, null, null);
921+
922+
if ($this->canUseSpinner($input, $output)) {
923+
$terminalWidth = (new Terminal)->getWidth();
924+
$description = mb_substr($command, 0, $terminalWidth - 6);
925+
926+
return spin(fn () => tap($process)->run(), "<fg=gray>{$description}...</>");
927+
}
902928

903929
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
904930
try {
@@ -908,13 +934,7 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
908934
}
909935
}
910936

911-
if ($this->canUseSpinner($input, $output)) {
912-
return spin(fn () => tap($process)->run(), 'Installing...');
913-
}
914-
915-
return tap($process)->run(function ($type, $line) use ($output) {
916-
$output->write(' '.$line);
917-
});
937+
return tap($process)->run();
918938
}
919939

920940
/**

0 commit comments

Comments
 (0)