Use constants for the output formats
This commit is contained in:
parent
01dc3935d0
commit
0a36331cb6
|
@ -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']);
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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'];
|
||||
|
|
Loading…
Reference in New Issue