Add autocomplete for db:* and log:*

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-09-21 14:21:39 +02:00 committed by Morris Jobke
parent 691a5d40a4
commit 8906b1cc95
5 changed files with 120 additions and 9 deletions

View File

@ -201,7 +201,7 @@ class Import extends Command implements CompletionAwareInterface {
/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]|false
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
return [];

View File

@ -31,6 +31,8 @@ namespace OC\Core\Command\Db;
use \OCP\IConfig;
use OC\DB\Connection;
use OC\DB\ConnectionFactory;
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\Helper\ProgressBar;
use Symfony\Component\Console\Helper\QuestionHelper;
@ -41,7 +43,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
class ConvertType extends Command {
class ConvertType extends Command implements CompletionAwareInterface {
/**
* @var \OCP\IConfig
*/
@ -350,4 +352,29 @@ class ConvertType extends Command {
'dbpassword' => $password,
]);
}
/**
* Return possible values for the named option
*
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
return [];
}
/**
* Return possible values for the named argument
*
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'type') {
return ['mysql', 'oci', 'pgsql'];
}
return [];
}
}

View File

@ -23,12 +23,16 @@
namespace OC\Core\Command\Db;
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 GenerateChangeScript extends Command {
class GenerateChangeScript extends Command implements CompletionAwareInterface {
protected function configure() {
$this
->setName('db:generate-change-script')
@ -56,4 +60,30 @@ class GenerateChangeScript extends Command {
}
}
/**
* @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 === 'schema-xml') {
$helper = new ShellPathCompletion(
$this->getName(),
'schema-xml',
Completion::TYPE_ARGUMENT
);
return $helper->run();
}
return [];
}
}

View File

@ -25,13 +25,15 @@ namespace OC\Core\Command\Log;
use \OCP\IConfig;
use Stecman\Component\Symfony\Console\BashCompletion\Completion;
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\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class File extends Command {
class File extends Command implements Completion\CompletionAwareInterface {
/** @var IConfig */
protected $config;
@ -125,4 +127,31 @@ class File extends Command {
}
}
/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
if ($optionName === 'file') {
$helper = new ShellPathCompletion(
$this->getName(),
'file',
Completion::TYPE_OPTION
);
return $helper->run();
} else if ($optionName === 'rotate-size') {
return [0];
}
return [];
}
/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
return [];
}
}

View File

@ -24,15 +24,15 @@
namespace OC\Core\Command\Log;
use \OCP\IConfig;
use OCP\IConfig;
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\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Manage extends Command {
class Manage extends Command implements CompletionAwareInterface {
const DEFAULT_BACKEND = 'file';
const DEFAULT_LOG_LEVEL = 2;
@ -172,4 +172,29 @@ class Manage extends Command {
}
throw new \InvalidArgumentException('Invalid log level number');
}
/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
if ($optionName === 'backend') {
return ['file', 'syslog', 'errorlog'];
} else if ($optionName === 'level') {
return ['debug', 'info', 'warning', 'error'];
} else if ($optionName === 'timezone') {
return \DateTimeZone::listIdentifiers();
}
return [];
}
/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
return [];
}
}