diff --git a/src/Commands/help/ListCommands.php b/src/Commands/help/ListCommands.php index c561abe7b2..f4582c5a4d 100644 --- a/src/Commands/help/ListCommands.php +++ b/src/Commands/help/ListCommands.php @@ -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; @@ -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]) { @@ -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); @@ -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; } }