Skip to content

Commit

Permalink
Fixes #132: Allowing multiple arguments for remote:drush command. (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash authored Jun 9, 2020
1 parent 5a3fdbf commit 5b63ca6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/Command/Remote/DrushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class DrushCommand extends SSHBaseCommand {
* {inheritdoc}.
*/
protected function configure() {
$this->setAliases(['drush'])
$this->setAliases(['drush', 'dr'])
->setDescription('Run a Drush command remotely on a application\'s environment')
->setHelp('Pleases pay close attention to the argument syntax! Note the usage of <comment>--</comment> to separate the drush command arguments and options.')
->addArgument('alias', InputArgument::REQUIRED, 'Alias for site & environment in the format `app-name.env`')
->addArgument('drush_command', InputArgument::REQUIRED, 'Drush command')
->addUsage(" <site>.<env> -- <command> Runs the Drush command <command> remotely on <site>'s <env> Cloud environment.")
->addUsage('@usage <site>.<env> --progress -- <command> Runs a Drush command with a progress bar');
->addArgument('drush_command', InputArgument::IS_ARRAY, 'Drush command')
->addUsage('<site>.<env> -- <command>')
->addUsage('mysite.dev -- uli 1')
->addUsage('mysite.dev -- status --fields=db-status');
}

/**
Expand All @@ -37,13 +39,14 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$alias = $this->validateAlias($input->getArgument('alias'));
$environment = $this->getEnvironmentFromAliasArg($alias);

$arguments = $input->getArguments();
// Remove 'remote:drush' command from array.
array_shift($arguments);
// Add command to array.
array_unshift($arguments, "cd /var/www/html/{$alias}/docroot; ", 'drush');
$acli_arguments = $input->getArguments();
$drush_command_arguments = [
"cd /var/www/html/{$alias}/docroot; ",
'drush',
implode(' ', (array) $acli_arguments['drush_command']),
];

return $this->sshHelper->executeCommand($environment, $arguments)->getExitCode();
return $this->sshHelper->executeCommand($environment, $drush_command_arguments)->getExitCode();
}

}
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/Remote/DrushCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testRemoteDrushCommand(): void {
'-o LogLevel=ERROR',
'cd /var/www/html/devcloud2.dev/docroot; ',
'drush',
'status',
'status --fields=db-status',
];
$local_machine_helper
->execute($ssh_command, Argument::type('callable'), NULL, TRUE)
Expand All @@ -51,7 +51,7 @@ public function testRemoteDrushCommand(): void {

$args = [
'alias' => 'devcloud2.dev',
'drush_command' => 'status',
'drush_command' => 'status --fields=db-status',
'-vvv' => '',
];
$this->executeCommand($args);
Expand Down

0 comments on commit 5b63ca6

Please sign in to comment.