Skip to content

Commit 2e26db2

Browse files
committed
chore: migrate update command to sprout
1 parent 4872ce4 commit 2e26db2

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

src/UpdateCommand.php

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,27 @@
44

55
namespace Leaf\Console;
66

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;
118

129
class UpdateCommand extends Command
1310
{
14-
protected static $defaultName = 'update';
11+
protected $signature = 'update';
1512

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';
2214

23-
protected function execute(InputInterface $input, OutputInterface $output): int
15+
protected function handle(): int
2416
{
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()) {
3418
sleep(1);
3519

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>');
4322
return 0;
4423
}
4524
}
4625

26+
$this->writeln('<error>Could not update CLI, please retry!</error>');
27+
4728
return 1;
4829
}
4930
}

0 commit comments

Comments
 (0)