Use constants for the output formats

This commit is contained in:
Joas Schilling 2015-07-17 09:25:19 +02:00
parent 01dc3935d0
commit 0a36331cb6
4 changed files with 12 additions and 8 deletions

View File

@ -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']);

View File

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

View File

@ -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 = [

View File

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