Skip to content

Commit

Permalink
Fix JSON output of list command and make XML output just be emitted b…
Browse files Browse the repository at this point in the history
…y Console as well.
  • Loading branch information
weitzman committed Feb 12, 2018
1 parent f0059f3 commit 4ea99f4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Commands/help/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Descriptor\JsonDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -28,7 +30,7 @@ class ListCommands extends DrushCommands
* @usage drush list --format=xml
* List all commands in Symfony compatible xml format.
*
* @return \DOMDocument
* @return string
*/
public function helpList($options = ['format' => 'listcli', 'raw' => false, 'filter' => self::REQ])
{
Expand All @@ -46,9 +48,10 @@ public function helpList($options = ['format' => 'listcli', 'raw' => false, 'fil
}

/**
* The listcli and raw formats don't yet go through the output formatter system.
* The listcli,json and raw formats don't yet go through the output formatter system.
* because \Consolidation\OutputFormatters\Transformations\DomToArraySimplifier
* can't yet handle the DomDocument that produces the Symfony expected XML.
* can't yet handle the DomDocument that produces the Symfony expected XML. For consistency, the XML
* output chooses to use the Symfony descriptor as well.
*/
if ($options['raw']) {
$this->renderListRaw($namespaced);
Expand All @@ -60,9 +63,16 @@ public function helpList($options = ['format' => 'listcli', 'raw' => false, 'fil
$this->io()->note(dt('Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands.'));
}
return null;
} elseif ($options['format'] == 'xml') {
$descriptor = new XmlDescriptor($this->output(), []);
return $descriptor->describe($this->output, $application, []);
} elseif ($options['format'] == 'json') {
$descriptor = new JsonDescriptor($this->output(), []);
return $descriptor->describe($this->output, $application, []);
} else {
$dom = $this->buildDom($namespaced, $application);
return $dom;
// No longer used. Works for XML, but gives error for JSON.
// $dom = $this->buildDom($namespaced, $application);
// return $dom;
}
}

Expand Down

0 comments on commit 4ea99f4

Please sign in to comment.