'json' => array(
'help' => 'Report results in JSON format.',
),
+ 'output' => array(
+ 'param' => 'format',
+ 'help' =>
+ "With 'full', show full pretty report (Default). ".
+ "With 'json', report results in JSON format. ".
+ "With 'ugly', use uglier (but more efficient) JSON formatting. ".
+ "With 'none', don't print results. ",
+ 'conflicts' => array(
+ 'json' => 'Only one output format allowed',
+ 'ugly' => 'Only one output format allowed',
+ )
+ ),
'everything' => array(
'help' => 'Run every test.',
'conflicts' => array(
$console = PhutilConsole::getConsole();
- $json_output = $this->getArgument('json');
+ $output_format = $this->getOutputFormat();
- if ($json_output) {
+ if ($output_format !== 'full') {
$console->disableOut();
}
}
}
- if ($json_output) {
+ if ($output_format !== 'full') {
$console->enableOut();
-
- $data = array_values(mpull($results, 'toDictionary'));
-
- if ($this->getArgument('ugly')) {
+ }
+ $data = array_values(mpull($results, 'toDictionary'));
+ switch ($output_format) {
+ case 'ugly':
$console->writeOut('%s', json_encode($data));
- } else {
+ break;
+ case 'json':
$json = new PhutilJSON();
$console->writeOut('%s', $json->encodeFormatted($data));
- }
+ break;
+ case 'full':
+ // already printed
+ break;
+ case 'none':
+ // do nothing
+ break;
}
return $overall_result;
return $out;
}
+
+ private function getOutputFormat() {
+ if ($this->getArgument('ugly')) {
+ return 'ugly';
+ }
+ if ($this->getArgument('json')) {
+ return 'json';
+ }
+ $format = $this->getArgument('output');
+ $known_formats = array(
+ 'none' => 'none',
+ 'json' => 'json',
+ 'ugly' => 'ugly',
+ 'full' => 'full',
+ );
+ return idx($known_formats, $format, 'full');
+ }
}