Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3025: Avoid validating args and options for remote proxy commands #3032

Merged
merged 2 commits into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Command/RemoteCommandProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drush\Symfony\IndiscriminateInputDefinition;

use Drush\Preflight\RedispatchHook;

Expand All @@ -30,6 +31,9 @@ public function __construct($name, RedispatchHook $redispatchHook)
parent::__construct($name);
$this->redispatchHook = $redispatchHook;

// Put in a special input definition to avoid option validation errors.
$this->setDefinition(new IndiscriminateInputDefinition());

// Put in a placeholder array arguement to avoid validation errors.
$this->addArgument(
'arguments',
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/PreflightArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Consolidation\Config\ConfigInterface;

use Symfony\Component\Console\Input\ArgvInput;
use Drush\Preflight\LessStrictArgvInput;
use Drush\Symfony\LessStrictArgvInput;

/**
* Storage for arguments preprocessed during preflight.
Expand Down
49 changes: 49 additions & 0 deletions src/Symfony/IndiscriminateInputDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Drush\Symfony;

use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;

/**
* This is an InputDefinition that allows any option to be considered valid.
* Used when passing a command through to anohter dispatcher that will do
* the option validation.
*
* We use this instead of a LessStrictArgvInput in cases where we do not
* know in advance whether the input should be handled indescriminately.
* In other words, an IndiscriminateInputDefinition is attached to individual
* Commands that should accept any option, whereas a LessStrictArgvInput
* should be used to make all command skip option validation.
*/
class IndiscriminateInputDefinition extends InputDefinition
{
/**
* @inheritdoc
*/
public function hasShortcut($name)
{
return true;
}

/**
* @inheritdoc
*/
public function hasOption($name)
{
return true;
}

/**
* @inheritdoc
*/
public function getOption($name)
{
if (parent::hasOption($name)) {
return parent::getOption($name);
}
return new InputOption($name, null, InputOption::VALUE_OPTIONAL, '', []);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Drush\Preflight;
namespace Drush\Symfony;

use Symfony\Component\Console\Input\ArgvInput;

Expand All @@ -12,6 +12,11 @@
*
* If the last argument of the command being called is not an array
* argument, then an error will be thrown if there are two many arguments.
*
* We use this instead of a IndiscriminateInputDefinition in cases where we
* know in advance that we wish to disable input validation for all commands.
* In contrast, an IndiscriminateInputDefinition is attached to individual
* Commands that should accept any option.
*/
class LessStrictArgvInput extends ArgvInput
{
Expand Down