|
4 | 4 |
|
5 | 5 | namespace Leaf\Console; |
6 | 6 |
|
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; |
12 | 8 |
|
13 | 9 | class RunCommand extends Command |
14 | 10 | { |
15 | | - protected static $defaultName = 'run'; |
| 11 | + protected $signature = 'run {script!: Command to run.}'; |
16 | 12 |
|
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'; |
24 | 14 |
|
25 | | - protected function execute(InputInterface $input, OutputInterface $output): int |
| 15 | + protected function handle(): int |
26 | 16 | { |
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>'); |
51 | 19 | return 1; |
52 | 20 | } |
53 | 21 |
|
54 | | - return 0; |
| 22 | + return (int) sprout() |
| 23 | + ->composer() |
| 24 | + ->runScript($this->argument('script')) |
| 25 | + ->isSuccessful(); |
55 | 26 | } |
56 | 27 | } |
0 commit comments