Skip to content

Commit c93fc46

Browse files
committed
chore: migrate uninstall command to sprout
1 parent 2e26db2 commit c93fc46

File tree

1 file changed

+9
-37
lines changed

1 file changed

+9
-37
lines changed

src/UninstallCommand.php

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,34 @@
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 UninstallCommand extends Command
1410
{
15-
protected static $defaultName = 'uninstall';
11+
protected $signature = 'uninstall {packages*}';
1612

17-
protected function configure()
18-
{
19-
$this
20-
->setHelp('The uninstall command removes a package from the current
21-
list of installed packages')
22-
->setDescription('Uninstall a package')
23-
->addArgument('packages', InputArgument::IS_ARRAY, 'package(s) to uninstall.');
24-
}
13+
protected $description = 'Uninstall a package';
2514

26-
protected function execute(InputInterface $input, OutputInterface $output): int
15+
protected function execute(): int
2716
{
28-
$packages = $input->getArgument('packages');
29-
30-
$composerJsonPath = getcwd() . '/composer.json';
31-
32-
if (!file_exists($composerJsonPath)) {
33-
$output->writeln('<error>No composer.json found in the current directory.</error>');
17+
$packages = $this->argument('packages');
3418

19+
if (!sprout()->composer()->json()) {
20+
$this->writeln('<error>No composer.json found in the current directory.</error>');
3521
return 1;
3622
}
3723

38-
$composer = Utils\Core::findComposer();
39-
4024
foreach ($packages as $package) {
4125
if (strpos($package, '/') == false) {
4226
$package = "leafs/$package";
4327
}
4428

45-
$process = Process::fromShellCommandline(
46-
"$composer remove $package",
47-
null,
48-
null,
49-
null,
50-
null
51-
);
52-
53-
$process->run(function ($type, $line) use ($output) {
54-
$output->write($line);
55-
});
56-
57-
if (!$process->isSuccessful()) {
29+
if (!sprout()->composer()->remove($package)->isSuccessful()) {
5830
return 1;
5931
}
6032
}
6133

62-
$output->writeln('<comment>packages uninstalled successfully!</comment>');
34+
$this->writeln('<comment>packages uninstalled successfully!</comment>');
6335

6436
return 0;
6537
}

0 commit comments

Comments
 (0)