|
|
|
|
@ -27,6 +27,12 @@ use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
$this
|
|
|
|
|
->addOption(
|
|
|
|
|
@ -34,7 +40,7 @@ class Base extends Command {
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_OPTIONAL,
|
|
|
|
|
'Output format (plain, json or json_pretty, default is plain)',
|
|
|
|
|
'plain'
|
|
|
|
|
$this->defaultOutputFormat
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
@ -47,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:
|
|
|
|
|
@ -87,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:
|
|
|
|
|
|