Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.31% |
61 / 64 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Uninstall | |
95.31% |
61 / 64 |
|
66.67% |
2 / 3 |
10 | |
0.00% |
0 / 1 |
| configure | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
83.33% |
15 / 18 |
|
0.00% |
0 / 1 |
5.12 | |||
| getRequestedResources | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Command; |
| 10 | |
| 11 | use OCA\Libresign\Service\Install\InstallTarget; |
| 12 | use Symfony\Component\Console\Input\InputInterface; |
| 13 | use Symfony\Component\Console\Input\InputOption; |
| 14 | use Symfony\Component\Console\Output\OutputInterface; |
| 15 | |
| 16 | class Uninstall extends Base { |
| 17 | #[\Override] |
| 18 | protected function configure(): void { |
| 19 | $this |
| 20 | ->setName('libresign:uninstall') |
| 21 | ->setDescription('Uninstall files') |
| 22 | ->addOption( |
| 23 | name: 'all', |
| 24 | shortcut: null, |
| 25 | mode: InputOption::VALUE_NONE, |
| 26 | description: 'All binaries' |
| 27 | ) |
| 28 | ->addOption( |
| 29 | name: 'jsignpdf', |
| 30 | shortcut: null, |
| 31 | mode: InputOption::VALUE_NONE, |
| 32 | description: 'JSignPdf' |
| 33 | ) |
| 34 | ->addOption( |
| 35 | name: 'pdftk', |
| 36 | shortcut: null, |
| 37 | mode: InputOption::VALUE_NONE, |
| 38 | description: 'PDFtk' |
| 39 | ) |
| 40 | ->addOption( |
| 41 | name: 'cfssl', |
| 42 | shortcut: null, |
| 43 | mode: InputOption::VALUE_NONE, |
| 44 | description: 'CFSSL' |
| 45 | ) |
| 46 | ->addOption( |
| 47 | name: 'java', |
| 48 | shortcut: null, |
| 49 | mode: InputOption::VALUE_NONE, |
| 50 | description: 'Java' |
| 51 | ) |
| 52 | ->addOption( |
| 53 | name: 'architecture', |
| 54 | shortcut: null, |
| 55 | mode: InputOption::VALUE_REQUIRED, |
| 56 | description: 'x86_64/amd64 or aarch64/arm64' |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | #[\Override] |
| 61 | protected function execute(InputInterface $input, OutputInterface $output): int { |
| 62 | try { |
| 63 | $architecture = (string)$input->getOption('architecture'); |
| 64 | if ($architecture !== '') { |
| 65 | $this->installService->setArchitecture( |
| 66 | InstallTarget::normalizeArchitecture($architecture), |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | $resources = $this->getRequestedResources($input); |
| 71 | if ($resources === []) { |
| 72 | $output->writeln('<error>Please inform what you want to uninstall</error>'); |
| 73 | $output->writeln('<error>--all to all</error>'); |
| 74 | $output->writeln('<error>--help to check the available options</error>'); |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | foreach ($resources as $resource) { |
| 79 | $this->installService->uninstall($resource); |
| 80 | } |
| 81 | } catch (\Exception $e) { |
| 82 | $this->logger->error($e->getMessage()); |
| 83 | throw $e; |
| 84 | } |
| 85 | |
| 86 | $output->writeln('Finished with success.'); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return list<string> |
| 92 | */ |
| 93 | private function getRequestedResources(InputInterface $input): array { |
| 94 | if ($input->getOption('all')) { |
| 95 | return array_values($this->installService->getAvailableResources()); |
| 96 | } |
| 97 | |
| 98 | $resources = []; |
| 99 | foreach ($this->installService->getAvailableResources() as $resource) { |
| 100 | if ($input->getOption($resource)) { |
| 101 | $resources[] = $resource; |
| 102 | } |
| 103 | } |
| 104 | return $resources; |
| 105 | } |
| 106 | } |