Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add autocomplete for db:* and log:*
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and MorrisJobke committed Sep 29, 2016
commit 8906b1cc95cfb729fcedeb40402d4e8855139096
2 changes: 1 addition & 1 deletion core/Command/Config/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function validateAppsArray($array) {
/**
* @param string $optionName
* @param CompletionContext $context
* @return string[]|false
* @return string[]
*/
public function completeOptionValues($optionName, CompletionContext $context) {
return [];
Expand Down
29 changes: 28 additions & 1 deletion core/Command/Db/ConvertType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
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;
Expand All @@ -41,7 +43,7 @@
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
*/
Expand Down Expand Up @@ -350,4 +352,29 @@ protected function saveDBInfo(InputInterface $input) {
'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 [];
}
}
32 changes: 31 additions & 1 deletion core/Command/Db/GenerateChangeScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -56,4 +60,30 @@ protected function execute(InputInterface $input, OutputInterface $output) {
}

}

/**
* @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 [];
}
}
33 changes: 31 additions & 2 deletions core/Command/Log/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

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;
Expand Down Expand Up @@ -125,4 +127,31 @@ protected function validateRotateSize(&$rotateSize) {
}
}

/**
* @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 [];
}
}
33 changes: 29 additions & 4 deletions core/Command/Log/Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -172,4 +172,29 @@ protected function convertLevelNumber($levelNum) {
}
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 [];
}
}