1
0
Fork 0

Merge pull request #4920 from curry684/issue-4918

Add a --timeout parameter to run-script to override default timeout
pull/4927/head
Jordi Boggiano 2016-02-16 13:33:00 +00:00
commit 93501a5e3f
2 changed files with 11 additions and 0 deletions

View File

@ -562,6 +562,7 @@ Lists the name, version and license of every package installed. Use
### Options ### Options
* **--timeout:** Set the script timeout in seconds, or 0 for no timeout.
* **--no-dev:** Disable dev mode * **--no-dev:** Disable dev mode
* **--list:** List user defined scripts * **--list:** List user defined scripts

View File

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\Script\CommandEvent; use Composer\Script\CommandEvent;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@ -50,6 +51,7 @@ class RunScriptCommand extends Command
->setDefinition(array( ->setDefinition(array(
new InputArgument('script', InputArgument::OPTIONAL, 'Script name to run.'), new InputArgument('script', InputArgument::OPTIONAL, 'Script name to run.'),
new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''), new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
new InputOption('timeout', null, InputOption::VALUE_REQUIRED, 'Sets script timeout in seconds, or 0 for never.'),
new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),
new InputOption('list', 'l', InputOption::VALUE_NONE, 'List scripts.'), new InputOption('list', 'l', InputOption::VALUE_NONE, 'List scripts.'),
@ -86,6 +88,14 @@ EOT
$args = $input->getArgument('args'); $args = $input->getArgument('args');
if (!is_null($timeout = $input->getOption('timeout'))) {
if (!ctype_digit($timeout)) {
throw new \RuntimeException('Timeout value must be numeric and positive if defined, or 0 for forever');
}
// Override global timeout set before in Composer by environment or config
ProcessExecutor::setTimeout((int)$timeout);
}
return $composer->getEventDispatcher()->dispatchScript($script, $input->getOption('dev') || !$input->getOption('no-dev'), $args); return $composer->getEventDispatcher()->dispatchScript($script, $input->getOption('dev') || !$input->getOption('no-dev'), $args);
} }