Refactor core/Command/App

Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
This commit is contained in:
Hamid Dehnavi 2023-07-06 11:30:27 +03:30 committed by Faraz Samapoor
parent f8f437072a
commit 81884cf9da
7 changed files with 22 additions and 15 deletions

View file

@ -83,7 +83,7 @@ class Disable extends Command implements CompletionAwareInterface {
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
public function completeOptionValues($optionName, CompletionContext $context): array {
return [];
}
@ -92,7 +92,7 @@ class Disable extends Command implements CompletionAwareInterface {
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app-id') {
return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps());
}

View file

@ -146,7 +146,7 @@ class Enable extends Command implements CompletionAwareInterface {
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
public function completeOptionValues($optionName, CompletionContext $context): array {
if ($optionName === 'groups') {
return array_map(function (IGroup $group) {
return $group->getGID();
@ -160,7 +160,7 @@ class Enable extends Command implements CompletionAwareInterface {
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app-id') {
$allApps = \OC_App::getAllApps();
return array_diff($allApps, \OC_App::getEnabledApps(true, true));

View file

@ -29,7 +29,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class GetPath extends Base {
protected function configure() {
protected function configure(): void {
parent::configure();
$this
@ -67,7 +67,7 @@ class GetPath extends Base {
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app') {
return \OC_App::getAllApps();
}

View file

@ -29,6 +29,8 @@ namespace OC\Core\Command\App;
use OC\Installer;
use OCP\App\IAppManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -36,7 +38,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Install extends Command {
protected function configure() {
protected function configure(): void {
$this
->setName('app:install')
->setDescription('install an app')
@ -66,6 +68,11 @@ class Install extends Command {
;
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$appId = $input->getArgument('app-id');
$forceEnable = (bool) $input->getOption('force');

View file

@ -39,7 +39,7 @@ class ListApps extends Base {
parent::__construct();
}
protected function configure() {
protected function configure(): void {
parent::configure();
$this
@ -98,7 +98,7 @@ class ListApps extends Base {
* @param OutputInterface $output
* @param array $items
*/
protected function writeAppList(InputInterface $input, OutputInterface $output, $items) {
protected function writeAppList(InputInterface $input, OutputInterface $output, $items): void {
switch ($input->getOption('output')) {
case self::OUTPUT_FORMAT_PLAIN:
$output->writeln('Enabled:');
@ -119,7 +119,7 @@ class ListApps extends Base {
* @param CompletionContext $context
* @return array
*/
public function completeOptionValues($optionName, CompletionContext $context) {
public function completeOptionValues($optionName, CompletionContext $context): array {
if ($optionName === 'shipped') {
return ['true', 'false'];
}
@ -131,7 +131,7 @@ class ListApps extends Base {
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
public function completeArgumentValues($argumentName, CompletionContext $context): array {
return [];
}
}

View file

@ -47,7 +47,7 @@ class Remove extends Command implements CompletionAwareInterface {
parent::__construct();
}
protected function configure() {
protected function configure(): void {
$this
->setName('app:remove')
->setDescription('remove an app')
@ -124,7 +124,7 @@ class Remove extends Command implements CompletionAwareInterface {
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
public function completeOptionValues($optionName, CompletionContext $context): array {
return [];
}
@ -133,7 +133,7 @@ class Remove extends Command implements CompletionAwareInterface {
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app-id') {
return \OC_App::getAllApps();
}

View file

@ -45,7 +45,7 @@ class Update extends Command {
parent::__construct();
}
protected function configure() {
protected function configure(): void {
$this
->setName('app:update')
->setDescription('update an app or all apps')