Skip to content

Commit

Permalink
Start using Drush’s own help and list commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Sep 1, 2017
1 parent 823d659 commit 45d2449
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/Commands/core/DrupliconCommands.php
Expand Up @@ -28,7 +28,7 @@ public function druplicon($result, CommandData $commandData)
$this->printed = true;
$annotationData = $commandData->annotationData();
$commandName = $annotationData['command'];
if ($commandData->input()->getOption('druplicon')) {
if ($commandData->input()->hasOption('druplicon') && $commandData->input()->getOption('druplicon')) {
$this->logger()->debug(dt('Displaying Druplicon for "!command" command.', array('!command' => $commandName)));
$misc_dir = DRUSH_BASE_PATH . '/misc';
if (drush_get_context('DRUSH_NOCOLOR')) {
Expand Down
12 changes: 4 additions & 8 deletions src/Commands/core/NotifyCommands.php
Expand Up @@ -39,19 +39,15 @@ public function registerShutdown(CommandData $commandData)

public function shutdown(CommandData $commandData)
{
$cmd = $commandData->input()->getFirstArgument();

$input = $commandData->input();
$cmd = $input->getFirstArgument();

if (empty($cmd)) {
return;
}

// pm-download handles its own notification.
if ($cmd != 'pm-download' && self::isAllowed($commandData)) {
$msg = $commandData->annotationData()->get('notify', dt("Command '!command' completed.", array('!command' => $cmd)));
$this->shutdownSend($msg, $commandData);
}

if ($commandData->input()->getOption('notify') && drush_get_error()) {
if ($input->hasOption('notify') && $input->getOption('notify') && drush_get_error()) {
// If the only error is that notify failed, do not try to notify again.
$log = drush_get_error_log();
if (count($log) == 1 && array_key_exists('NOTIFY_COMMAND_NOT_FOUND', $log)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/StatusCommands.php
Expand Up @@ -17,7 +17,7 @@ class StatusCommands extends DrushCommands
/**
* @command core-status
* @param $filter A field to filter on. @deprecated - use --field option instead.
* @option project A comma delimited list of projects. their paths will be added to path-aliases section.
* @option project A comma delimited list of projects. Their paths will be added to path-aliases section.
* @aliases status, st
*n
* @table-style compact
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/XhprofCommands.php
Expand Up @@ -64,7 +64,7 @@ public function xhprofInitialize(InputInterface $input, AnnotationData $annotati

public static function xhprofIsEnabled(InputInterface $input)
{
if ($input->getOption('xh-link')) {
if ($input->hasOption('xh-link') && $input->getOption('xh-link')) {
if (!extension_loaded('xhprof') && !extension_loaded('tideways')) {
throw new \Exception(dt('You must enable the xhprof or tideways PHP extensions in your CLI PHP in order to profile.'));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/help/HelpCommands.php
Expand Up @@ -13,7 +13,7 @@ class HelpCommands extends DrushCommands
* Display usage details for a command.
*
* @command help
* @param $name A command name
* @param $command_name A command name
* @usage drush help pm-uninstall
* Show help for a command.
* @usage drush help pmu
Expand All @@ -27,10 +27,10 @@ class HelpCommands extends DrushCommands
*
* @return \Consolidation\AnnotatedCommand\Help\HelpDocument
*/
public function help($name, $options = ['format' => 'helpcli', 'include-field-labels' => false, 'table-style' => 'compact'])
public function help($command_name, $options = ['format' => 'helpcli', 'include-field-labels' => false, 'table-style' => 'compact'])
{
$application = Drush::getApplication();
$command = $application->get($name);
$command = $application->get($command_name);
if ($command instanceof AnnotatedCommand) {
$command->optionsHook();
}
Expand All @@ -49,7 +49,7 @@ public function help($name, $options = ['format' => 'helpcli', 'include-field-la
*/
public function validate(CommandData $commandData)
{
$name = $commandData->input()->getArgument('name');
$name = $commandData->input()->getArgument('command_name');
if (empty($name)) {
throw new \Exception(dt("The help command requires that a command name be provided. Run `drush list` to see a list of available commands."));
} else {
Expand Down
28 changes: 1 addition & 27 deletions src/Commands/help/ListCommands.php
Expand Up @@ -30,7 +30,7 @@ class ListCommands extends DrushCommands
*
* @return \DOMDocument
*/
public function helpList($filter, $options = ['format' => 'listcli', 'raw' => false, 'filter' => null])
public function helpList($filter = null, $options = ['format' => 'listcli', 'raw' => false, 'filter' => null])
{
$application = Drush::getApplication();
annotation_adapter_add_legacy_commands_to_application($application);
Expand Down Expand Up @@ -123,32 +123,6 @@ public static function renderListCLI($application, $namespaced, $output, $preamb
->writeln($preamble);
$output->writeln('');

// For now ,this table does not need TableFormatter.
$table = new Table($output);
$table->setStyle('compact');
$global_options_help = drush_get_global_options(true);
$options = $application->getDefinition()->getOptions();
// Only display this table for Drush help, not 'generate' command.
if ($application->getName() == 'Drush Commandline Tool') {
$table->addRow([new TableCell('Global options. See `drush topic core-global-options` for the full list.', array('colspan' => 2))]);
foreach ($global_options_help as $key => $help) {
$data = [
'name' => '--' . $options[$key]->getName(),
'description' => $help['description'],
// Not using $options[$key]->getDescription() as description is too long for -v
'accept_value' => $options[$key]->acceptValue(),
'is_value_required' => $options[$key]->isValueRequired(),
'shortcut' => $options[$key]->getShortcut(),
];
$table->addRow([
HelpCLIFormatter::formatOptionKeys($data),
HelpCLIFormatter::formatOptionDescription($data)
]);
}
$table->addRow(['', '']);
$table->render();
}

$rows[] = ['Available commands:', ''];
foreach ($namespaced as $namespace => $list) {
$rows[] = [$namespace . ':', ''];
Expand Down
5 changes: 0 additions & 5 deletions src/Preflight/Preflight.php
Expand Up @@ -195,11 +195,6 @@ protected function doRun($argv)
$discovery = $this->commandDiscovery();
$commandClasses = $discovery->discover($searchpath, '\Drush');

// For now: use Symfony's built-in help, as Drush's version
// assumes we are using the legacy Drush dispatcher.
unset($commandClasses[dirname(__DIR__) . '/Commands/help/HelpCommands.php']);
unset($commandClasses[dirname(__DIR__) . '/Commands/help/ListCommands.php']);

// Use the robo runner to register commands with Symfony application.
$runner = new \Robo\Runner();
$runner->registerCommandClasses($application, $commandClasses);
Expand Down

0 comments on commit 45d2449

Please sign in to comment.