From d5dcb60e5d796852cf62183c388605793bb89c09 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Jul 2015 17:51:33 +0200 Subject: [PATCH 1/3] Use json_pretty as default for the config lists (for easier export/import) --- core/command/base.php | 4 +++- core/command/config/listconfigs.php | 7 ++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/command/base.php b/core/command/base.php index 7e61c0cb9a..7936e683dc 100644 --- a/core/command/base.php +++ b/core/command/base.php @@ -27,6 +27,8 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Base extends Command { + protected $defaultOutputFormat = 'plain'; + protected function configure() { $this ->addOption( @@ -34,7 +36,7 @@ class Base extends Command { null, InputOption::VALUE_OPTIONAL, 'Output format (plain, json or json_pretty, default is plain)', - 'plain' + $this->defaultOutputFormat ) ; } diff --git a/core/command/config/listconfigs.php b/core/command/config/listconfigs.php index be3073e54d..d80bd2b98c 100644 --- a/core/command/config/listconfigs.php +++ b/core/command/config/listconfigs.php @@ -30,6 +30,8 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ListConfigs extends Base { + protected $defaultOutputFormat = 'json_pretty'; + /** @var array */ protected $sensitiveValues = [ 'dbpassword', @@ -81,11 +83,6 @@ class ListConfigs extends Base { $app = $input->getArgument('app'); $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) { case 'system': $configs = [ From 01dc3935d03cb08703b47bfeef50dcbb7f5458e7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Jul 2015 17:54:04 +0200 Subject: [PATCH 2/3] Add app and config name to error messages --- core/command/config/app/deleteconfig.php | 4 ++-- core/command/config/app/setconfig.php | 2 +- core/command/config/system/deleteconfig.php | 2 +- core/command/config/system/setconfig.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/command/config/app/deleteconfig.php b/core/command/config/app/deleteconfig.php index 0031142358..bc031b0d58 100644 --- a/core/command/config/app/deleteconfig.php +++ b/core/command/config/app/deleteconfig.php @@ -70,12 +70,12 @@ class DeleteConfig extends Base { $configName = $input->getArgument('name'); if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) { - $output->writeln('Config ' . $configName . ' could not be deleted because it did not exist'); + $output->writeln('Config ' . $configName . ' of app ' . $appName . ' could not be deleted because it did not exist'); return 1; } $this->config->deleteAppValue($appName, $configName); - $output->writeln('System config value ' . $configName . ' deleted'); + $output->writeln('Config value ' . $configName . ' of app ' . $appName . ' deleted'); return 0; } } diff --git a/core/command/config/app/setconfig.php b/core/command/config/app/setconfig.php index 91775094fd..eea58a63c5 100644 --- a/core/command/config/app/setconfig.php +++ b/core/command/config/app/setconfig.php @@ -76,7 +76,7 @@ class SetConfig extends Base { $configName = $input->getArgument('name'); if (!in_array($configName, $this->config->getAppKeys($appName)) && $input->hasParameterOption('--update-only')) { - $output->writeln('Value not updated, as it has not been set before.'); + $output->writeln('Config value ' . $configName . ' for app ' . $appName . ' not updated, as it has not been set before.'); return 1; } diff --git a/core/command/config/system/deleteconfig.php b/core/command/config/system/deleteconfig.php index 49bc2bc8c0..4d193647c8 100644 --- a/core/command/config/system/deleteconfig.php +++ b/core/command/config/system/deleteconfig.php @@ -64,7 +64,7 @@ class DeleteConfig extends Base { $configName = $input->getArgument('name'); if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { - $output->writeln('Config ' . $configName . ' could not be deleted because it did not exist'); + $output->writeln('System config ' . $configName . ' could not be deleted because it did not exist'); return 1; } diff --git a/core/command/config/system/setconfig.php b/core/command/config/system/setconfig.php index cb2f9fe616..82b36cca16 100644 --- a/core/command/config/system/setconfig.php +++ b/core/command/config/system/setconfig.php @@ -70,7 +70,7 @@ class SetConfig extends Base { $configName = $input->getArgument('name'); if (!in_array($configName, $this->systemConfig->getKeys()) && $input->hasParameterOption('--update-only')) { - $output->writeln('Value not updated, as it has not been set before.'); + $output->writeln('Config value ' . $configName . ' not updated, as it has not been set before.'); return 1; } $configValue = $input->getOption('value'); From 0a36331cb614770b5d004ca193126fce650bcd55 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jul 2015 09:25:19 +0200 Subject: [PATCH 3/3] Use constants for the output formats --- core/command/app/listapps.php | 2 +- core/command/base.php | 14 +++++++++----- core/command/config/listconfigs.php | 2 +- core/command/encryption/listmodules.php | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/command/app/listapps.php b/core/command/app/listapps.php index e30baddb74..e483037d45 100644 --- a/core/command/app/listapps.php +++ b/core/command/app/listapps.php @@ -73,7 +73,7 @@ class ListApps extends Base { */ protected function writeAppList(InputInterface $input, OutputInterface $output, $items) { switch ($input->getOption('output')) { - case 'plain': + case self::OUTPUT_FORMAT_PLAIN: $output->writeln('Enabled:'); parent::writeArrayInOutputFormat($input, $output, $items['enabled']); diff --git a/core/command/base.php b/core/command/base.php index 7936e683dc..0a4b002c1c 100644 --- a/core/command/base.php +++ b/core/command/base.php @@ -27,7 +27,11 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Base extends Command { - protected $defaultOutputFormat = 'plain'; + 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() { $this @@ -49,10 +53,10 @@ class Base extends Command { */ protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { switch ($input->getOption('output')) { - case 'json': + case self::OUTPUT_FORMAT_JSON: $output->writeln(json_encode($items)); break; - case 'json_pretty': + case self::OUTPUT_FORMAT_JSON_PRETTY: $output->writeln(json_encode($items, JSON_PRETTY_PRINT)); break; default: @@ -89,10 +93,10 @@ class Base extends Command { } switch ($input->getOption('output')) { - case 'json': + case self::OUTPUT_FORMAT_JSON: $output->writeln(json_encode($item)); break; - case 'json_pretty': + case self::OUTPUT_FORMAT_JSON_PRETTY: $output->writeln(json_encode($item, JSON_PRETTY_PRINT)); break; default: diff --git a/core/command/config/listconfigs.php b/core/command/config/listconfigs.php index d80bd2b98c..fed6a8e9db 100644 --- a/core/command/config/listconfigs.php +++ b/core/command/config/listconfigs.php @@ -30,7 +30,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ListConfigs extends Base { - protected $defaultOutputFormat = 'json_pretty'; + protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; /** @var array */ protected $sensitiveValues = [ diff --git a/core/command/encryption/listmodules.php b/core/command/encryption/listmodules.php index d55480def8..cc436ea562 100644 --- a/core/command/encryption/listmodules.php +++ b/core/command/encryption/listmodules.php @@ -65,7 +65,7 @@ class ListModules extends Base { * @param array $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) { if (!$item['default']) { $item = $item['displayName'];