diff options
author | Joas Schilling <coding@schilljs.com> | 2016-09-21 14:03:09 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2016-09-29 15:57:10 +0200 |
commit | 691a5d40a4420c15a23db0f49f67a7fb1ecf7738 (patch) | |
tree | c29a44406a3cffc03750da5703ec5febb91790e5 /core/Command | |
parent | e1df6b5702224bbbdc4ed555ecc90620ba9b0e40 (diff) | |
download | nextcloud-server-691a5d40a4420c15a23db0f49f67a7fb1ecf7738.tar.gz nextcloud-server-691a5d40a4420c15a23db0f49f67a7fb1ecf7738.zip |
Add autocomplete for config:*
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/Command')
-rw-r--r-- | core/Command/Base.php | 3 | ||||
-rw-r--r-- | core/Command/Config/App/Base.php | 48 | ||||
-rw-r--r-- | core/Command/Config/App/DeleteConfig.php | 1 | ||||
-rw-r--r-- | core/Command/Config/App/GetConfig.php | 1 | ||||
-rw-r--r-- | core/Command/Config/App/SetConfig.php | 1 | ||||
-rw-r--r-- | core/Command/Config/Import.php | 32 | ||||
-rw-r--r-- | core/Command/Config/ListConfigs.php | 13 | ||||
-rw-r--r-- | core/Command/Config/System/Base.php | 78 | ||||
-rw-r--r-- | core/Command/Config/System/DeleteConfig.php | 1 | ||||
-rw-r--r-- | core/Command/Config/System/GetConfig.php | 1 | ||||
-rw-r--r-- | core/Command/Config/System/SetConfig.php | 13 |
11 files changed, 185 insertions, 7 deletions
diff --git a/core/Command/Base.php b/core/Command/Base.php index 1a78e3b4062..15878a807d8 100644 --- a/core/Command/Base.php +++ b/core/Command/Base.php @@ -167,6 +167,9 @@ class Base extends Command implements CompletionAwareInterface { * @return string[] */ public function completeOptionValues($optionName, CompletionContext $context) { + if ($optionName === 'output') { + return ['plain', 'json', 'json_pretty']; + } return []; } diff --git a/core/Command/Config/App/Base.php b/core/Command/Config/App/Base.php new file mode 100644 index 00000000000..3f29591dd15 --- /dev/null +++ b/core/Command/Config/App/Base.php @@ -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 []; + } +} diff --git a/core/Command/Config/App/DeleteConfig.php b/core/Command/Config/App/DeleteConfig.php index 82099556ca1..9cb28c9774c 100644 --- a/core/Command/Config/App/DeleteConfig.php +++ b/core/Command/Config/App/DeleteConfig.php @@ -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; diff --git a/core/Command/Config/App/GetConfig.php b/core/Command/Config/App/GetConfig.php index eb81b1b19b0..fe365c2546d 100644 --- a/core/Command/Config/App/GetConfig.php +++ b/core/Command/Config/App/GetConfig.php @@ -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; diff --git a/core/Command/Config/App/SetConfig.php b/core/Command/Config/App/SetConfig.php index aa84ddf1d8e..e7f5c8ac61b 100644 --- a/core/Command/Config/App/SetConfig.php +++ b/core/Command/Config/App/SetConfig.php @@ -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; diff --git a/core/Command/Config/Import.php b/core/Command/Config/Import.php index a27d1b62f0b..15517f860a5 100644 --- a/core/Command/Config/Import.php +++ b/core/Command/Config/Import.php @@ -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 */ @@ -193,4 +197,30 @@ class Import extends Command { } } } + + /** + * @param string $optionName + * @param CompletionContext $context + * @return string[]|false + */ + 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 []; + } } diff --git a/core/Command/Config/ListConfigs.php b/core/Command/Config/ListConfigs.php index e11eec1a7a1..2737bc2cea4 100644 --- a/core/Command/Config/ListConfigs.php +++ b/core/Command/Config/ListConfigs.php @@ -25,6 +25,7 @@ namespace OC\Core\Command\Config; 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; @@ -127,4 +128,16 @@ class ListConfigs extends Base { 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 []; + } } diff --git a/core/Command/Config/System/Base.php b/core/Command/Config/System/Base.php new file mode 100644 index 00000000000..4e49baf5ab2 --- /dev/null +++ b/core/Command/Config/System/Base.php @@ -0,0 +1,78 @@ +<?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\System; + +use OC\SystemConfig; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; + +abstract class Base extends \OC\Core\Command\Base { + + /** @var SystemConfig */ + protected $systemConfig; + + /** + * @param string $argumentName + * @param CompletionContext $context + * @return string[] + */ + public function completeArgumentValues($argumentName, CompletionContext $context) { + if ($argumentName === 'name') { + $words = $this->getPreviousNames($context, $context->getWordIndex()); + if (empty($words)) { + $completions = $this->systemConfig->getKeys(); + } else { + $key = array_shift($words); + $value = $this->systemConfig->getValue($key); + $completions = array_keys($value); + + while (!empty($words) && is_array($value)) { + $key = array_shift($words); + if (!isset($value[$key]) || !is_array($value[$key])) { + break; + } + + $value = $value[$key]; + $completions = array_keys($value); + } + } + + return $completions; + } + return parent::completeArgumentValues($argumentName, $context); + } + + /** + * @param CompletionContext $context + * @param int $currentIndex + * @return string[] + */ + protected function getPreviousNames(CompletionContext $context, $currentIndex) { + $word = $context->getWordAtIndex($currentIndex - 1); + if ($word === $this->getName() || $currentIndex <= 0) { + return []; + } + + $words = $this->getPreviousNames($context, $currentIndex - 1); + $words[] = $word; + return $words; + } +} diff --git a/core/Command/Config/System/DeleteConfig.php b/core/Command/Config/System/DeleteConfig.php index 65f26f7b2a8..216cf4eb640 100644 --- a/core/Command/Config/System/DeleteConfig.php +++ b/core/Command/Config/System/DeleteConfig.php @@ -22,7 +22,6 @@ namespace OC\Core\Command\Config\System; -use OC\Core\Command\Base; use OC\SystemConfig; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/core/Command/Config/System/GetConfig.php b/core/Command/Config/System/GetConfig.php index 7c2f663e42c..11ead7456cc 100644 --- a/core/Command/Config/System/GetConfig.php +++ b/core/Command/Config/System/GetConfig.php @@ -22,7 +22,6 @@ namespace OC\Core\Command\Config\System; -use OC\Core\Command\Base; use OC\SystemConfig; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/core/Command/Config/System/SetConfig.php b/core/Command/Config/System/SetConfig.php index fcbf3c0baa5..992fca8d084 100644 --- a/core/Command/Config/System/SetConfig.php +++ b/core/Command/Config/System/SetConfig.php @@ -23,8 +23,8 @@ namespace OC\Core\Command\Config\System; -use OC\Core\Command\Base; use OC\SystemConfig; +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; @@ -196,4 +196,15 @@ class SetConfig extends Base { return $existingValues; } + /** + * @param string $optionName + * @param CompletionContext $context + * @return string[] + */ + public function completeOptionValues($optionName, CompletionContext $context) { + if ($optionName === 'type') { + return ['string', 'integer', 'double', 'boolean']; + } + return parent::completeOptionValues($optionName, $context); + } } |