Skip to content

Commit

Permalink
Merge pull request #7 from digipolisgent/feature/issue-6
Browse files Browse the repository at this point in the history
Issue #6: Fix too many arguments error.
  • Loading branch information
Jelle-S authored Feb 2, 2017
2 parents d674b39 + 6b36e16 commit 083a65e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
29 changes: 26 additions & 3 deletions src/DrupalConsoleStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
class DrupalConsoleStack extends CommandStack
{

use CommandArguments;
use CommandArguments {
option as optionNoEqualSign;
}

/**
* Verbosity levels:
Expand Down Expand Up @@ -89,6 +91,27 @@ public function __construct($pathToDrupalConsole = 'drupal')
$this->executable = $pathToDrupalConsole;
}

/**
* Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter.
* Option values are automatically escaped.
*
* @param string $option
* The option name.
* @param string $value
* The option value.
*
* @return $this
*/
public function option($option, $value = null)
{
if (!is_null($option) && strpos($option, '-') !== 0) {
$option = "--$option";
}
$this->arguments .= is_null($option) ? '' : " " . $option;
$this->arguments .= is_null($value) ? '' : "=" . static::escape($value);
return $this;
}

/**
* Pass an option to the executable; applies to the next command only.
*
Expand Down Expand Up @@ -732,8 +755,8 @@ protected function injectArguments($command, $assumeYes)
{
$optionsForNextCmd = '';
foreach ($this->optionsForNextCmd as $option => $value) {
$optionsForNextCmd .= ' --'.$option.(
is_null($value) ? '' : ' '.static::escape($value)
$optionsForNextCmd .= ' --' . $option . (
is_null($value) ? '' : '=' . static::escape($value)
);
}
$cmd = $command;
Expand Down
42 changes: 21 additions & 21 deletions tests/DrupalConsoleStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testOptionsArePrependedBeforeEachCommand()
->drupal('command-1')
->drupal('command-2')
->getCommand();
$this->assertRegExp('#--root /var/www/html/app#', $command);
$this->assertRegExp('#--root=/var/www/html/app#', $command);
}

/**
Expand Down Expand Up @@ -300,7 +300,7 @@ public function testListCommandOutsideDrupalSite()
public function testDrupalRootDirectoryOption()
{
$this->assertEquals(
'drupal command --root '.static::escape(__DIR__),
'drupal command --root='.static::escape(__DIR__),
$this->getTestOptionCommand('drupalRootDirectory', __DIR__)
);
}
Expand All @@ -311,7 +311,7 @@ public function testDrupalRootDirectoryOption()
public function testUriOption()
{
$this->assertEquals(
'drupal command --uri '.static::escape('http://example.com'),
'drupal command --uri='.static::escape('http://example.com'),
$this->getTestOptionCommand('uri', 'http://example.com')
);
}
Expand All @@ -322,7 +322,7 @@ public function testUriOption()
public function testEnvironmentOption()
{
$this->assertEquals(
'drupal command --env prod',
'drupal command --env=prod',
$this->getTestOptionCommand('environment', 'prod')
);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ public function testVerboseOption()
];
foreach ($levels as $level) {
$this->assertEquals(
'drupal command --verbose '.$level,
'drupal command --verbose='.$level,
$this->getTestOptionCommand('verbose', $level)
);
}
Expand All @@ -362,7 +362,7 @@ public function testVerboseOption()
public function testSiteNameOption()
{
$this->assertEquals(
'drupal command --site-name Digipolis',
'drupal command --site-name=Digipolis',
$this->getTestOptionCommand('siteName', 'Digipolis')
);
}
Expand All @@ -373,7 +373,7 @@ public function testSiteNameOption()
public function testSiteMailOption()
{
$this->assertEquals(
'drupal command --site-mail digipolis@example.com',
'drupal command --site-mail=digipolis@example.com',
$this->getTestOptionCommand('siteMail', 'digipolis@example.com')
);
}
Expand All @@ -384,7 +384,7 @@ public function testSiteMailOption()
public function testFileOption()
{
$this->assertEquals(
'drupal command --file '.static::escape(__FILE__),
'drupal command --file='.static::escape(__FILE__),
$this->getTestOptionCommand('file', __FILE__)
);
}
Expand All @@ -395,7 +395,7 @@ public function testFileOption()
public function testDirectoryOption()
{
$this->assertEquals(
'drupal command --directory '.static::escape(__DIR__),
'drupal command --directory='.static::escape(__DIR__),
$this->getTestOptionCommand('directory', __DIR__)
);
}
Expand All @@ -417,7 +417,7 @@ public function testTarOption()
public function testLangcodeOption()
{
$this->assertEquals(
'drupal command --langcode nl',
'drupal command --langcode=nl',
$this->getTestOptionCommand('langcode', 'nl')
);
}
Expand All @@ -428,7 +428,7 @@ public function testLangcodeOption()
public function testDbTypeOption()
{
$this->assertEquals(
'drupal command --db-type mysql',
'drupal command --db-type=mysql',
$this->getTestOptionCommand('dbType', 'mysql')
);
}
Expand All @@ -439,7 +439,7 @@ public function testDbTypeOption()
public function testDbFileOption()
{
$this->assertEquals(
'drupal command --db-file .h.sqlite',
'drupal command --db-file=.h.sqlite',
$this->getTestOptionCommand('dbFile', '.h.sqlite')
);
}
Expand All @@ -450,7 +450,7 @@ public function testDbFileOption()
public function testDbHostOption()
{
$this->assertEquals(
'drupal command --db-host localhost',
'drupal command --db-host=localhost',
$this->getTestOptionCommand('dbHost', 'localhost')
);
}
Expand All @@ -461,7 +461,7 @@ public function testDbHostOption()
public function testDbNameOption()
{
$this->assertEquals(
'drupal command --db-name db_digipolis',
'drupal command --db-name=db_digipolis',
$this->getTestOptionCommand('dbName', 'db_digipolis')
);
}
Expand All @@ -472,7 +472,7 @@ public function testDbNameOption()
public function testDbUserOption()
{
$this->assertEquals(
'drupal command --db-user db_user',
'drupal command --db-user=db_user',
$this->getTestOptionCommand('dbUser', 'db_user')
);
}
Expand All @@ -483,7 +483,7 @@ public function testDbUserOption()
public function testDbPassOption()
{
$this->assertEquals(
'drupal command --db-pass db_pass',
'drupal command --db-pass=db_pass',
$this->getTestOptionCommand('dbPass', 'db_pass')
);
}
Expand All @@ -494,7 +494,7 @@ public function testDbPassOption()
public function testDbPrefixOption()
{
$this->assertEquals(
'drupal command --db-prefix prefix_',
'drupal command --db-prefix=prefix_',
$this->getTestOptionCommand('dbPrefix', 'prefix_')
);
}
Expand All @@ -505,7 +505,7 @@ public function testDbPrefixOption()
public function testDbPortOption()
{
$this->assertEquals(
'drupal command --db-port 1234',
'drupal command --db-port=1234',
$this->getTestOptionCommand('dbPort', '1234')
);
}
Expand All @@ -516,7 +516,7 @@ public function testDbPortOption()
public function testAccountMailOption()
{
$this->assertEquals(
'drupal command --account-mail account@example.com',
'drupal command --account-mail=account@example.com',
$this->getTestOptionCommand('accountMail', 'account@example.com')
);
$this->getTestOptionCommand(
Expand All @@ -532,7 +532,7 @@ public function testAccountMailOption()
public function testAccountNameOption()
{
$this->assertEquals(
'drupal command --account-name accountName',
'drupal command --account-name=accountName',
$this->getTestOptionCommand('accountName', 'accountName')
);
$this->getTestOptionCommand(
Expand All @@ -548,7 +548,7 @@ public function testAccountNameOption()
public function testAccountPassOption()
{
$this->assertEquals(
'drupal command --account-pass MyPwD123_',
'drupal command --account-pass=MyPwD123_',
$this->getTestOptionCommand('accountPass', 'MyPwD123_')
);
$this->getTestOptionCommand('accountPass', 'account-pass', 'MyPwD123_');
Expand Down

0 comments on commit 083a65e

Please sign in to comment.