Skip to content

Commit 2ce066d

Browse files
committed
feat: migrate run command to sprout
1 parent 549efce commit 2ce066d

File tree

1 file changed

+10
-39
lines changed

1 file changed

+10
-39
lines changed

src/RunCommand.php

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,24 @@
44

55
namespace Leaf\Console;
66

7-
use Symfony\Component\Console\Command\Command;
8-
use Symfony\Component\Console\Input\InputArgument;
9-
use Symfony\Component\Console\Input\InputInterface;
10-
use Symfony\Component\Console\Output\OutputInterface;
11-
use Symfony\Component\Process\Process;
7+
use Leaf\Sprout\Command;
128

139
class RunCommand extends Command
1410
{
15-
protected static $defaultName = 'run';
11+
protected $signature = 'run {script!: Command to run.}';
1612

17-
protected function configure()
18-
{
19-
$this
20-
->setHelp('Run a composer script')
21-
->setDescription('Run a script in your composer.json')
22-
->addArgument('scriptName', InputArgument::REQUIRED, 'Command to run.');
23-
}
13+
protected $description = 'Run a script in your composer.json';
2414

25-
protected function execute(InputInterface $input, OutputInterface $output): int
15+
protected function handle(): int
2616
{
27-
$composerJsonPath = getcwd() . '/composer.json';
28-
29-
if (!file_exists($composerJsonPath)) {
30-
$output->writeln('<error>No composer.json found in the current directory.</error>');
31-
32-
return 1;
33-
}
34-
35-
$script = $input->getArgument('scriptName');
36-
$composer = Utils\Core::findComposer();
37-
38-
$process = Process::fromShellCommandline(
39-
"$composer run $script",
40-
null,
41-
null,
42-
null,
43-
null
44-
);
45-
46-
$process->run(function ($type, $line) use ($output) {
47-
$output->write($line);
48-
});
49-
50-
if (!$process->isSuccessful()) {
17+
if (!sprout()->composer()->json()) {
18+
$this->writeln('<error>No composer.json found in the current directory.</error>');
5119
return 1;
5220
}
5321

54-
return 0;
22+
return (int) sprout()
23+
->composer()
24+
->runScript($this->argument('script'))
25+
->isSuccessful();
5526
}
5627
}

0 commit comments

Comments
 (0)