Skip to content
Snippets Groups Projects
Commit 1e458f18 authored by Morris Jobke's avatar Morris Jobke
Browse files

Merge pull request #17686 from owncloud/fix-occ-config-commands

Fix occ config commands
parents bcfa18c0 0a36331c
No related branches found
No related tags found
No related merge requests found
...@@ -73,7 +73,7 @@ class ListApps extends Base { ...@@ -73,7 +73,7 @@ class ListApps extends Base {
*/ */
protected function writeAppList(InputInterface $input, OutputInterface $output, $items) { protected function writeAppList(InputInterface $input, OutputInterface $output, $items) {
switch ($input->getOption('output')) { switch ($input->getOption('output')) {
case 'plain': case self::OUTPUT_FORMAT_PLAIN:
$output->writeln('Enabled:'); $output->writeln('Enabled:');
parent::writeArrayInOutputFormat($input, $output, $items['enabled']); parent::writeArrayInOutputFormat($input, $output, $items['enabled']);
......
...@@ -27,6 +27,12 @@ use Symfony\Component\Console\Input\InputOption; ...@@ -27,6 +27,12 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class Base extends Command { class Base extends Command {
const OUTPUT_FORMAT_PLAIN = 'plain';
const OUTPUT_FORMAT_JSON = 'json';
const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty';
protected $defaultOutputFormat = self::OUTPUT_FORMAT_PLAIN;
protected function configure() { protected function configure() {
$this $this
->addOption( ->addOption(
...@@ -34,7 +40,7 @@ class Base extends Command { ...@@ -34,7 +40,7 @@ class Base extends Command {
null, null,
InputOption::VALUE_OPTIONAL, InputOption::VALUE_OPTIONAL,
'Output format (plain, json or json_pretty, default is plain)', 'Output format (plain, json or json_pretty, default is plain)',
'plain' $this->defaultOutputFormat
) )
; ;
} }
...@@ -47,10 +53,10 @@ class Base extends Command { ...@@ -47,10 +53,10 @@ class Base extends Command {
*/ */
protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') {
switch ($input->getOption('output')) { switch ($input->getOption('output')) {
case 'json': case self::OUTPUT_FORMAT_JSON:
$output->writeln(json_encode($items)); $output->writeln(json_encode($items));
break; break;
case 'json_pretty': case self::OUTPUT_FORMAT_JSON_PRETTY:
$output->writeln(json_encode($items, JSON_PRETTY_PRINT)); $output->writeln(json_encode($items, JSON_PRETTY_PRINT));
break; break;
default: default:
...@@ -87,10 +93,10 @@ class Base extends Command { ...@@ -87,10 +93,10 @@ class Base extends Command {
} }
switch ($input->getOption('output')) { switch ($input->getOption('output')) {
case 'json': case self::OUTPUT_FORMAT_JSON:
$output->writeln(json_encode($item)); $output->writeln(json_encode($item));
break; break;
case 'json_pretty': case self::OUTPUT_FORMAT_JSON_PRETTY:
$output->writeln(json_encode($item, JSON_PRETTY_PRINT)); $output->writeln(json_encode($item, JSON_PRETTY_PRINT));
break; break;
default: default:
......
...@@ -70,12 +70,12 @@ class DeleteConfig extends Base { ...@@ -70,12 +70,12 @@ class DeleteConfig extends Base {
$configName = $input->getArgument('name'); $configName = $input->getArgument('name');
if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) { if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) {
$output->writeln('<error>Config ' . $configName . ' could not be deleted because it did not exist</error>'); $output->writeln('<error>Config ' . $configName . ' of app ' . $appName . ' could not be deleted because it did not exist</error>');
return 1; return 1;
} }
$this->config->deleteAppValue($appName, $configName); $this->config->deleteAppValue($appName, $configName);
$output->writeln('<info>System config value ' . $configName . ' deleted</info>'); $output->writeln('<info>Config value ' . $configName . ' of app ' . $appName . ' deleted</info>');
return 0; return 0;
} }
} }
...@@ -76,7 +76,7 @@ class SetConfig extends Base { ...@@ -76,7 +76,7 @@ class SetConfig extends Base {
$configName = $input->getArgument('name'); $configName = $input->getArgument('name');
if (!in_array($configName, $this->config->getAppKeys($appName)) && $input->hasParameterOption('--update-only')) { if (!in_array($configName, $this->config->getAppKeys($appName)) && $input->hasParameterOption('--update-only')) {
$output->writeln('<comment>Value not updated, as it has not been set before.</comment>'); $output->writeln('<comment>Config value ' . $configName . ' for app ' . $appName . ' not updated, as it has not been set before.</comment>');
return 1; return 1;
} }
......
...@@ -30,6 +30,8 @@ use Symfony\Component\Console\Input\InputOption; ...@@ -30,6 +30,8 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class ListConfigs extends Base { class ListConfigs extends Base {
protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY;
/** @var array */ /** @var array */
protected $sensitiveValues = [ protected $sensitiveValues = [
'dbpassword', 'dbpassword',
...@@ -81,11 +83,6 @@ class ListConfigs extends Base { ...@@ -81,11 +83,6 @@ class ListConfigs extends Base {
$app = $input->getArgument('app'); $app = $input->getArgument('app');
$noSensitiveValues = !$input->getOption('private'); $noSensitiveValues = !$input->getOption('private');
if ($noSensitiveValues && !$input->hasParameterOption('--output')) {
// If you post this publicly we prefer the json format
$input->setOption('output', 'json_pretty');
}
switch ($app) { switch ($app) {
case 'system': case 'system':
$configs = [ $configs = [
......
...@@ -64,7 +64,7 @@ class DeleteConfig extends Base { ...@@ -64,7 +64,7 @@ class DeleteConfig extends Base {
$configName = $input->getArgument('name'); $configName = $input->getArgument('name');
if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
$output->writeln('<error>Config ' . $configName . ' could not be deleted because it did not exist</error>'); $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>');
return 1; return 1;
} }
......
...@@ -70,7 +70,7 @@ class SetConfig extends Base { ...@@ -70,7 +70,7 @@ class SetConfig extends Base {
$configName = $input->getArgument('name'); $configName = $input->getArgument('name');
if (!in_array($configName, $this->systemConfig->getKeys()) && $input->hasParameterOption('--update-only')) { if (!in_array($configName, $this->systemConfig->getKeys()) && $input->hasParameterOption('--update-only')) {
$output->writeln('<comment>Value not updated, as it has not been set before.</comment>'); $output->writeln('<comment>Config value ' . $configName . ' not updated, as it has not been set before.</comment>');
return 1; return 1;
} }
$configValue = $input->getOption('value'); $configValue = $input->getOption('value');
......
...@@ -65,7 +65,7 @@ class ListModules extends Base { ...@@ -65,7 +65,7 @@ class ListModules extends Base {
* @param array $items * @param array $items
*/ */
protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) {
if ($input->getOption('output') === 'plain') { if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
array_walk($items, function(&$item) { array_walk($items, function(&$item) {
if (!$item['default']) { if (!$item['default']) {
$item = $item['displayName']; $item = $item['displayName'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment