|
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 UninstallCommand extends Command |
14 | 10 | { |
15 | | - protected static $defaultName = 'uninstall'; |
| 11 | + protected $signature = 'uninstall {packages*}'; |
16 | 12 |
|
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'; |
25 | 14 |
|
26 | | - protected function execute(InputInterface $input, OutputInterface $output): int |
| 15 | + protected function execute(): int |
27 | 16 | { |
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'); |
34 | 18 |
|
| 19 | + if (!sprout()->composer()->json()) { |
| 20 | + $this->writeln('<error>No composer.json found in the current directory.</error>'); |
35 | 21 | return 1; |
36 | 22 | } |
37 | 23 |
|
38 | | - $composer = Utils\Core::findComposer(); |
39 | | - |
40 | 24 | foreach ($packages as $package) { |
41 | 25 | if (strpos($package, '/') == false) { |
42 | 26 | $package = "leafs/$package"; |
43 | 27 | } |
44 | 28 |
|
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()) { |
58 | 30 | return 1; |
59 | 31 | } |
60 | 32 | } |
61 | 33 |
|
62 | | - $output->writeln('<comment>packages uninstalled successfully!</comment>'); |
| 34 | + $this->writeln('<comment>packages uninstalled successfully!</comment>'); |
63 | 35 |
|
64 | 36 | return 0; |
65 | 37 | } |
|
0 commit comments