]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add output-json option to arc feature
authorChris Dentel <cdentel@fb.com>
Mon, 25 Nov 2013 19:50:11 +0000 (11:50 -0800)
committerepriestley <git@epriestley.com>
Mon, 25 Nov 2013 19:50:11 +0000 (11:50 -0800)
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

src/workflow/ArcanistFeatureWorkflow.php

index d9830fa70764eb54db98556a3feb7bd09a999a00..5fcbaaf7a2316f7dfda3e865f0e929db0683d0ec 100644 (file)
@@ -60,6 +60,13 @@ EOTEXT
       'by-status' => array(
         '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',
     );
   }
@@ -324,8 +331,10 @@ EOTEXT
         'current'   => $branch['current'],
         'status'    => $status,
         'desc'      => $desc,
+        'revision'  => $revision ? $revision['id'] : null,
         'color'     => $color,
         'esort'     => $epoch,
+        'epoch'     => $epoch,
         'ssort'     => $ssort,
       );
     }
@@ -338,16 +347,22 @@ EOTEXT
     } else {
       $out = isort($out, 'esort');
     }
-
-    $console = PhutilConsole::getConsole();
-    foreach ($out as $line) {
-      $color = $line['color'];
-      $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']);
+    if ($this->getArgument('output') == 'json') {
+      foreach ($out as &$feature) {
+        unset($feature['color'], $feature['ssort'], $feature['esort']);
+      }
+      echo json_encode(ipull($out, null, 'name')) . "\n";
+    } else {
+      $console = PhutilConsole::getConsole();
+      foreach ($out as $line) {
+        $color = $line['color'];
+        $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']);
+      }
     }
   }