Skip to content
This repository was archived by the owner on Jun 26, 2019. It is now read-only.

Commit

Permalink
Add OptionsCommands for sharing options providers (drush-ops#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman authored Dec 16, 2016
1 parent 0e2b6dc commit 1b14090
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 36 deletions.
12 changes: 11 additions & 1 deletion includes/annotationcommand_adapter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,17 @@ function annotationcommand_adapter_add_hook_options(&$command)
// the extension hook a core command, or have an early-loaded global
// extension hook a late-loaded extension (e.g. attached to a module).
$names = annotationcommand_adapter_command_names($command);
$names[] = '*'; // we are missing annotations here; maybe we just don't support that? (TODO later, maybe)
$names[] = '*';
// Add possible hooks.
$blacklist = ['command', 'handle-remote-commands', 'strict-option-handling', 'allow-additional-options', 'bootstrap', 'topic', 'hidden', 'hidden-option'];
/** @var \Consolidation\AnnotatedCommand\AnnotationData $annotationData */
$annotationData = $command['annotations'];
$keys = array_diff($annotationData->keys(), $blacklist);
$atkeys = [];
foreach ($keys as $key) {
$atkeys[] = '@'. $key;
}
$names = array_merge($names, $atkeys);
$factory = \Drush::commandFactory();
$extraOptions = $factory->hookManager()->getHookOptions($names);
foreach ($extraOptions as $commandinfo) {
Expand Down
12 changes: 0 additions & 12 deletions includes/exec.inc
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,6 @@ function drush_shell_proc_open($cmd) {
return 0;
}

/**
* Used by definition of ssh and other commands that call into drush_shell_proc_build()
* to declare their options.
*/
function drush_shell_exec_proc_build_options() {
return array(
'ssh-options' => 'A string of extra options that will be passed to the ssh command (e.g. "-p 100")',
'tty' => 'Create a tty (e.g. to run an interactive program).',
'escaped' => 'Command string already escaped; do not add additional quoting.',
);
}

/**
* Determine the appropriate os value for the
* specified site record
Expand Down
5 changes: 1 addition & 4 deletions lib/Drush/Commands/DrushCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
use Robo\Contract\IOAwareInterface;
use Robo\Common\IO;

abstract class DrushCommands implements
IOAwareInterface,
LoggerAwareInterface
{
abstract class DrushCommands implements IOAwareInterface, LoggerAwareInterface {
use LoggerAwareTrait;
use IO {
io as roboIo;
Expand Down
26 changes: 26 additions & 0 deletions lib/Drush/Commands/OptionsCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace Drush\Commands;

/*
* Common options providers. Use them by adding an annotation to your method.
*/
class OptionsCommands {

/**
* @hook option @optionset_proc_build
* @option ssh-options A string of extra options that will be passed to the ssh command (e.g. "-p 100")
* @option tty Create a tty (e.g. to run an interactive program).
* @option escaped Command string already escaped; do not add additional quoting.
*/
public function optionset_proc_build() {}

/**
* @hook option @optionset_get_editor
* @option editor A string of bash which launches user's preferred text editor. Defaults to ${VISUAL-${EDITOR-vi}}.
* @option bg Run editor in the background. Does not work with editors such as `vi` that run in the terminal.
*/
public function optionset_get_editor() {}

}


2 changes: 1 addition & 1 deletion lib/Drush/Commands/core/CoreCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function version($options = ['format' => 'table']) {
* @command core-execute
* @param $command The shell command to be executed.
* @option escape Escape parameters before executing them with the shell. Default is escape; use --no-escape to disable.
* @proc_build_options
* @optionset_proc_build
* @allow-additional-options
* @handle-remote-commands
* @strict-option-handling
Expand Down
2 changes: 1 addition & 1 deletion lib/Drush/Commands/core/EditCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EditCommands extends DrushCommands {
* @command core-edit
* @bootstrap DRUSH_BOOTSTRAP_MAX
* @param $filter A substring for filtering the list of files. Omit this argument to choose from loaded files.
* @todo global-options' => array('editor', 'bg'),
* @optionset_get_editor
* @usage drush core-config
* Pick from a list of config/alias/settings files. Open selected in editor.
* @usage drush --bg core-config
Expand Down
24 changes: 15 additions & 9 deletions lib/Drush/Commands/core/InitCommands.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
<?php
namespace Drush\Commands\core;

use Drush\Commands\DrushCommands;
use Drush\Log\LogLevel;
use Robo\LoadAllTasks;
use Robo\Contract\IOAwareInterface;
use Robo\Contract\BuilderAwareInterface;

class InitCommands extends \Robo\Tasks

class InitCommands extends DrushCommands implements BuilderAwareInterface, IOAwareInterface
{

use LoadAllTasks;

/**
* Initialize local Drush configuration
* Enrich the bash startup file with completion and aliases.
*
* @command core-init
*
* @todo: @global-options
*
* @description Enrich the bash startup file with completion and aliases.
* @option $edit Open the new config file in an editor.
* @option $add-path Always add Drush to the \$PATH in the user's .bashrc
* file, even if it is already in the \$PATH. Use --no-add-path to skip
* updating .bashrc with the Drush \$PATH. Default is to update .bashrc
* only if Drush is not already in the \$PATH.
* @option $add-path Always add Drush to the $PATH in the user's .bashrc
* file, even if it is already in the $PATH. Use --no-add-path to skip
* updating .bashrc with the Drush $PATH. Default is to update .bashrc
* only if Drush is not already in the $PATH.
* @optionset_get_editor
* @aliases init
* @usage core-init --edit
* Enrich Bash and open drush config file in editor.
Expand Down
9 changes: 1 addition & 8 deletions lib/Drush/Commands/core/SshCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SshCommands extends DrushCommands {
* @command site-ssh
* @param string $bash Bash to execute on target. Optional, except when site-alias is a list.
* @option cd Directory to change to if Drupal root is not desired (the default). Value should be a full path, or --no-cd for the ssh default (usually the remote user's home directory).
* @optionset_proc_build
* @handle-remote-commands
* @strict-option-handling
* @usage drush @mysite ssh
Expand Down Expand Up @@ -73,12 +74,4 @@ public function ssh($bash = '', $options = ['cd' => TRUE]) {
throw new \Exception(dt('An error @code occurred while running the command `@command`', array('@command' => $cmd, '@code' => $status)));
}
}

/**
* @hook option site-ssh
* @option ssh-options A string of extra options that will be passed to the ssh command (e.g. "-p 100")',
* @option tty Create a tty (e.g. to run an interactive program).',
* @option escaped Command string already escaped; do not add additional quoting.',
*/
public function proc_build_options() {}
}

0 comments on commit 1b14090

Please sign in to comment.