Skip to content

Commit

Permalink
Merge pull request #1 from dustinleblanc/master
Browse files Browse the repository at this point in the history
Allow commands to initiate a prompt
  • Loading branch information
boedah committed Sep 20, 2015
2 parents 46c8220 + 6ae41eb commit 323ab6a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Extension to execute Drush commands in [Robo](https://github.com/Codegyre/Robo).

Runs Drush commands in stack. You can define global options for all commands (like Drupal root and uri).

The option -y is always set, as it makes sense in a task runner.
The option -y assumed by default but can be overridden on calls to `exec()` by passing `false` as the second parameter.

## Table of contents

Expand Down
22 changes: 12 additions & 10 deletions src/DrushStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,26 +317,28 @@ public function siteInstall($installationProfile)
* Runs the given drush command.
*
* @param string $command
* @param bool $prompt
* @return $this
*/
public function exec($command)
public function exec($command, $assumeYes = true)
{
if (is_array($command)) {
$command = implode(' ', array_filter($command));
}

return parent::exec($this->injectArguments($command));
return parent::exec($this->injectArguments($command, $assumeYes));
}

/**
* Prepends site-alias and appends arguments to the command.
*
* @param string $command
* @return string the modified command string
*/
protected function injectArguments($command)
/**
* Prepends site-alias and appends arguments to the command.
*
* @param string $command
* @param bool $assumeYes
* @return string the modified command string
*/
protected function injectArguments($command, $assumeYes)
{
return $this->siteAlias . ' ' . $command . ' -y' . $this->arguments;
return $this->siteAlias . ' ' . $command . ($assumeYes ? ' -y' : '') . $this->arguments;
}

}
8 changes: 8 additions & 0 deletions tests/DrushStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public function testYesIsAssumed()
$this->assertEquals('drush command -y', $command);
}

public function testAbsenceofYes()
{
$command = $this->taskDrushStack()
->exec('command', false)
->getCommand();
$this->assertEquals('drush command', $command);
}

public function testOptionsArePrependedBeforeEachCommand()
{
$command = $this->taskDrushStack()
Expand Down

0 comments on commit 323ab6a

Please sign in to comment.