|
4 | 4 |
|
5 | 5 | namespace Leaf\Console; |
6 | 6 |
|
7 | | -use Symfony\Component\Console\Command\Command; |
8 | | -use Symfony\Component\Console\Input\InputInterface; |
9 | | -use Symfony\Component\Console\Output\OutputInterface; |
10 | | -use Symfony\Component\Process\Process; |
| 7 | +use Leaf\Sprout\Command; |
11 | 8 |
|
12 | 9 | class UpdateCommand extends Command |
13 | 10 | { |
14 | | - protected static $defaultName = 'update'; |
| 11 | + protected $signature = 'update'; |
15 | 12 |
|
16 | | - protected function configure() |
17 | | - { |
18 | | - $this |
19 | | - ->setHelp('Update leaf cli') |
20 | | - ->setDescription('Update leaf cli to the latest version'); |
21 | | - } |
| 13 | + protected $description = 'Update leaf cli to the latest version'; |
22 | 14 |
|
23 | | - protected function execute(InputInterface $input, OutputInterface $output): int |
| 15 | + protected function handle(): int |
24 | 16 | { |
25 | | - $composer = Utils\Core::findComposer(); |
26 | | - $uninstall = Process::fromShellCommandline("$composer global remove leafs/cli --no-update --no-install"); |
27 | | - $install = Process::fromShellCommandline("$composer global require leafs/cli", null, null, null, null); |
28 | | - |
29 | | - $uninstall->run(function ($type, $line) use ($output) { |
30 | | - $output->write($line); |
31 | | - }); |
32 | | - |
33 | | - if ($uninstall->isSuccessful()) { |
| 17 | + if (sprout()->composer(true)->remove('cli --no-update --no-install')->isSuccessful()) { |
34 | 18 | sleep(1); |
35 | 19 |
|
36 | | - $install->run(function ($type, $line) use ($output) { |
37 | | - $output->write($line); |
38 | | - }); |
39 | | - |
40 | | - if ($install->isSuccessful()) { |
41 | | - $output->writeln('<info>Leaf CLI installed successfully!</info>'); |
42 | | - |
| 20 | + if (sprout()->composer(true)->install('cli')->isSuccessful()) { |
| 21 | + $this->writeln('<info>Leaf CLI installed successfully!</info>'); |
43 | 22 | return 0; |
44 | 23 | } |
45 | 24 | } |
46 | 25 |
|
| 26 | + $this->writeln('<error>Could not update CLI, please retry!</error>'); |
| 27 | + |
47 | 28 | return 1; |
48 | 29 | } |
49 | 30 | } |
0 commit comments