Add autocomplete for config:*

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/1476/head
Joas Schilling 9 years ago committed by Morris Jobke
parent e1df6b5702
commit 691a5d40a4
  1. 3
      core/Command/Base.php
  2. 48
      core/Command/Config/App/Base.php
  3. 1
      core/Command/Config/App/DeleteConfig.php
  4. 1
      core/Command/Config/App/GetConfig.php
  5. 1
      core/Command/Config/App/SetConfig.php
  6. 32
      core/Command/Config/Import.php
  7. 13
      core/Command/Config/ListConfigs.php
  8. 78
      core/Command/Config/System/Base.php
  9. 1
      core/Command/Config/System/DeleteConfig.php
  10. 1
      core/Command/Config/System/GetConfig.php
  11. 13
      core/Command/Config/System/SetConfig.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 [];
}

@ -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 [];
}
}

@ -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;

@ -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;

@ -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;

@ -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 [];
}
}

@ -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 [];
}
}

@ -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;
}
}

@ -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;

@ -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;

@ -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);
}
}

Loading…
Cancel
Save