Skip to content

Commit

Permalink
Merge pull request #3 from guncha25/feature/drush-default-options
Browse files Browse the repository at this point in the history
Feature/drush default options
  • Loading branch information
guncha25 committed Jan 2, 2019
2 parents 568f814 + d3312eb commit 33e0e50
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ modules:
- DrupalDrush:
working_directory: './web'
drush: './vendor/bin/drush'
options:
uri: http://mydomain.com
root: /app/web
```

### Usage
Expand Down
33 changes: 32 additions & 1 deletion src/Codeception/Module/DrupalDrush.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* - DrupalDrush:
* working_directory: './web'
* drush: './vendor/bin/drush'
* options:
* uri: http://mydomain.com
* root: /app/web
*
* @package Codeception\Module
*/
Expand All @@ -26,6 +29,7 @@ class DrupalDrush extends Module {
*/
protected $config = [
'drush' => 'drush',
'options' => [],
];

/**
Expand All @@ -34,14 +38,41 @@ class DrupalDrush extends Module {
* @param string $command
* Command to run.
* e.g. "en devel -y".
* @param array $options
* Associative array of options.
*
* @return string
* The process output.
*/
public function runDrush($command) {
public function runDrush($command, array $options = []) {
if (!empty($options)) {
$command = $this->normalizeOptions($options) . $command;
}
elseif ($this->_getConfig('options')) {
$command = $this->normalizeOptions($this->_getConfig('options')) . $command;
}
return Drush::runDrush($command, $this->_getConfig('drush'), $this->_getConfig('working_directory'));
}

/**
* Returns options as sting.
*
* @param array $options
* Associative array of options.
*
* @return string
* Sring of options.
*/
protected function normalizeOptions(array $options) {
$command = '';
foreach ($options as $key => $value) {
if (is_string($value)) {
$command .= '--' . $key . '=' . $value . ' ';
}
}
return $command;
}

/**
* Gets login uri.
*
Expand Down

0 comments on commit 33e0e50

Please sign in to comment.