Skip to content

Commit

Permalink
Merge pull request #1476 from nextcloud/autocomplete-for-occ-app-comm…
Browse files Browse the repository at this point in the history
…ands

Autocomplete for occ app commands
  • Loading branch information
MorrisJobke committed Sep 29, 2016
2 parents 8a14f4a + 6188955 commit ffaf2f3
Show file tree
Hide file tree
Showing 29 changed files with 558 additions and 36 deletions.
28 changes: 27 additions & 1 deletion core/Command/App/CheckCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
use OC\App\CodeChecker\EmptyCheck;
use OC\App\CodeChecker\InfoChecker;
use OC\App\InfoParser;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CheckCode extends Command {
class CheckCode extends Command implements CompletionAwareInterface {

/** @var InfoParser */
private $infoParser;
Expand Down Expand Up @@ -197,4 +199,28 @@ private function analyseUpdateFile($appId, OutputInterface $output) {
$output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>");
}
}

/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
if ($optionName === 'checker') {
return ['private', 'deprecation', 'strong-comparison'];
}
return [];
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app-id') {
return \OC_App::getAllApps();
}
return [];
}
}
25 changes: 24 additions & 1 deletion core/Command/App/Disable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
namespace OC\Core\Command\App;

use OCP\App\IAppManager;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Disable extends Command {
class Disable extends Command implements CompletionAwareInterface {

/** @var IAppManager */
protected $manager;
Expand Down Expand Up @@ -69,4 +71,25 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('No such app enabled: ' . $appId);
}
}

/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
return [];
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app-id') {
return array_diff(\OC_App::getEnabledApps(true, true), $this->manager->getAlwaysEnabledApps());
}
return [];
}
}
32 changes: 31 additions & 1 deletion core/Command/App/Enable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
namespace OC\Core\Command\App;

use OCP\App\IAppManager;
use OCP\IGroup;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Enable extends Command {
class Enable extends Command implements CompletionAwareInterface {

/** @var IAppManager */
protected $manager;
Expand Down Expand Up @@ -81,4 +84,31 @@ protected function execute(InputInterface $input, OutputInterface $output) {
}
return 0;
}

/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
if ($optionName === 'groups') {
return array_map(function(IGroup $group) {
return $group->getGID();
}, \OC::$server->getGroupManager()->search($context->getCurrentWord()));
}
return [];
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app-id') {
$allApps = \OC_App::getAllApps();
return array_diff($allApps, \OC_App::getEnabledApps(true, true));
}
return [];
}
}
13 changes: 13 additions & 0 deletions core/Command/App/GetPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OC\Core\Command\App;

use OC\Core\Command\Base;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -60,4 +61,16 @@ protected function execute(InputInterface $input, OutputInterface $output) {
// App not found, exit with non-zero
return 1;
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app') {
return \OC_App::getAllApps();
}
return [];
}
}
22 changes: 22 additions & 0 deletions core/Command/App/ListApps.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use OC\Core\Command\Base;
use OCP\App\IAppManager;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -117,4 +118,25 @@ protected function writeAppList(InputInterface $input, OutputInterface $output,
break;
}
}

/**
* @param string $optionName
* @param CompletionContext $completionContext
* @return array
*/
public function completeOptionValues($optionName, CompletionContext $completionContext) {
if ($optionName === 'shipped') {
return ['true', 'false'];
}
return [];
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
return [];
}
}
25 changes: 24 additions & 1 deletion core/Command/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

namespace OC\Core\Command;

use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Base extends Command {
class Base extends Command implements CompletionAwareInterface {
const OUTPUT_FORMAT_PLAIN = 'plain';
const OUTPUT_FORMAT_JSON = 'json';
const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty';
Expand Down Expand Up @@ -158,4 +160,25 @@ public function run(InputInterface $input, OutputInterface $output) {

return parent::run($input, $output);
}

/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
if ($optionName === 'output') {
return ['plain', 'json', 'json_pretty'];
}
return [];
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
return [];
}
}
48 changes: 48 additions & 0 deletions core/Command/Config/App/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OC\Core\Command\Config\App;

use OCP\IConfig;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;

abstract class Base extends \OC\Core\Command\Base {

/** * @var IConfig */
protected $config;

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app') {
return \OC_App::getAllApps();
}

if ($argumentName === 'name') {
$appName = $context->getWordAtIndex($context->getWordIndex() - 1);
return $this->config->getAppKeys($appName);
}
return [];
}
}
1 change: 0 additions & 1 deletion core/Command/Config/App/DeleteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace OC\Core\Command\Config\App;

use OC\Core\Command\Base;
use OCP\IConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
1 change: 0 additions & 1 deletion core/Command/Config/App/GetConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace OC\Core\Command\Config\App;

use OC\Core\Command\Base;
use OCP\IConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
1 change: 0 additions & 1 deletion core/Command/Config/App/SetConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace OC\Core\Command\Config\App;

use OC\Core\Command\Base;
use OCP\IConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
32 changes: 31 additions & 1 deletion core/Command/Config/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
namespace OC\Core\Command\Config;

use OCP\IConfig;
use Stecman\Component\Symfony\Console\BashCompletion\Completion;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\ShellPathCompletion;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Import extends Command {
class Import extends Command implements CompletionAwareInterface {
protected $validRootKeys = ['system', 'apps'];

/** @var IConfig */
Expand Down Expand Up @@ -193,4 +197,30 @@ protected function validateAppsArray($array) {
}
}
}

/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
return [];
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'file') {
$helper = new ShellPathCompletion(
$this->getName(),
'file',
Completion::TYPE_ARGUMENT
);
return $helper->run();
}
return [];
}
}
13 changes: 13 additions & 0 deletions core/Command/Config/ListConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OC\Core\Command\Base;
use OC\SystemConfig;
use OCP\IAppConfig;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -127,4 +128,16 @@ protected function getSystemConfigs($noSensitiveValues) {

return $configs;
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app') {
return array_merge(['all', 'system'], \OC_App::getAllApps());
}
return [];
}
}
Loading

0 comments on commit ffaf2f3

Please sign in to comment.