1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-26 00:32:41 +01:00

Add output-json option to arc feature

Summary:
The current format of arc feature is not very friendly to parsing.  This adds a json output
format.

Test Plan: Run the command and ensure output is valid

Reviewers: lifeihuang, #blessed_reviewers, epriestley

Reviewed By: epriestley

CC: epriestley, aran, Korvin

Differential Revision: https://secure.phabricator.com/D7647
This commit is contained in:
Chris Dentel 2013-11-25 11:50:11 -08:00 committed by epriestley
parent 799841a0d8
commit d30c77d0a8

View file

@ -60,6 +60,13 @@ EOTEXT
'by-status' => array( 'by-status' => array(
'help' => 'Sort branches by status instead of time.', 'help' => 'Sort branches by status instead of time.',
), ),
'output' => array(
'param' => 'format',
'support' => array(
'json'
),
'help' => "With 'json', show features in machine-readable JSON format.",
),
'*' => 'branch', '*' => 'branch',
); );
} }
@ -324,8 +331,10 @@ EOTEXT
'current' => $branch['current'], 'current' => $branch['current'],
'status' => $status, 'status' => $status,
'desc' => $desc, 'desc' => $desc,
'revision' => $revision ? $revision['id'] : null,
'color' => $color, 'color' => $color,
'esort' => $epoch, 'esort' => $epoch,
'epoch' => $epoch,
'ssort' => $ssort, 'ssort' => $ssort,
); );
} }
@ -338,16 +347,22 @@ EOTEXT
} else { } else {
$out = isort($out, 'esort'); $out = isort($out, 'esort');
} }
if ($this->getArgument('output') == 'json') {
$console = PhutilConsole::getConsole(); foreach ($out as &$feature) {
foreach ($out as $line) { unset($feature['color'], $feature['ssort'], $feature['esort']);
$color = $line['color']; }
$console->writeOut( echo json_encode(ipull($out, null, 'name')) . "\n";
"%s **%s** <fg:{$color}>%s</fg> %s\n", } else {
$line['current'] ? '* ' : ' ', $console = PhutilConsole::getConsole();
str_pad($line['name'], $len_name), foreach ($out as $line) {
str_pad($line['status'], $len_status), $color = $line['color'];
$line['desc']); $console->writeOut(
"%s **%s** <fg:{$color}>%s</fg> %s\n",
$line['current'] ? '* ' : ' ',
str_pad($line['name'], $len_name),
str_pad($line['status'], $len_status),
$line['desc']);
}
} }
} }