Skip to content

Commit 2354173

Browse files
mortensongreg-1-anderson
authored andcommitted
Allow Symfony Console commands to be used in php:cli. (#3770)
1 parent 76e9e81 commit 2354173

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/Psysh/DrushCommand.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Drush\Psysh;
1111

1212
use Consolidation\AnnotatedCommand\AnnotatedCommand;
13+
use Symfony\Component\Console\Command\Command;
1314
use Psy\Command\Command as BaseCommand;
1415
use Symfony\Component\Console\Formatter\OutputFormatter;
1516
use Symfony\Component\Console\Input\InputInterface;
@@ -22,17 +23,17 @@ class DrushCommand extends BaseCommand
2223
{
2324

2425
/**
25-
* @var \Consolidation\AnnotatedCommand\AnnotatedCommand
26+
* @var \Symfony\Component\Console\Command\Command
2627
*/
2728
private $command;
2829

2930
/**
3031
* DrushCommand constructor.
3132
*
32-
* @param \Consolidation\AnnotatedCommand\AnnotatedCommand $command
33-
* Original (annotated) Drush command.
33+
* @param \Symfony\Component\Console\Command\Command $command
34+
* Original Drush command.
3435
*/
35-
public function __construct(AnnotatedCommand $command)
36+
public function __construct(Command $command)
3637
{
3738
$this->command = $command;
3839
parent::__construct();
@@ -110,14 +111,17 @@ protected function buildHelpFromCommand()
110111
$help = wordwrap($this->command->getDescription());
111112

112113
$examples = [];
113-
foreach ($this->command->getExampleUsages() as $ex => $def) {
114-
// Skip empty examples and things with obvious pipes...
115-
if (($ex === '') || (strpos($ex, '|') !== false)) {
116-
continue;
117-
}
118114

119-
$ex = preg_replace('/^drush\s+/', '', $ex);
120-
$examples[$ex] = $def;
115+
if ($this->command instanceof AnnotatedCommand) {
116+
foreach ($this->command->getExampleUsages() as $ex => $def) {
117+
// Skip empty examples and things with obvious pipes...
118+
if (($ex === '') || (strpos($ex, '|') !== false)) {
119+
continue;
120+
}
121+
122+
$ex = preg_replace('/^drush\s+/', '', $ex);
123+
$examples[$ex] = $def;
124+
}
121125
}
122126

123127
if (!empty($examples)) {

0 commit comments

Comments
 (0)