Skip to content
Permalink
Browse files

Merge pull request #4920 from curry684/issue-4918

Add a --timeout parameter to run-script to override default timeout
  • Loading branch information...
Seldaek committed Feb 16, 2016
2 parents aea6045 + 126e71a commit 93501a5e3f8433e982da3518e13896ee4c0e816b
Showing with 11 additions and 0 deletions.
  1. +1 −0 doc/03-cli.md
  2. +10 −0 src/Composer/Command/RunScriptCommand.php
@@ -562,6 +562,7 @@ Lists the name, version and license of every package installed. Use
### Options
* **--timeout:** Set the script timeout in seconds, or 0 for no timeout.
* **--no-dev:** Disable dev mode
* **--list:** List user defined scripts
@@ -14,6 +14,7 @@
use Composer\Script\CommandEvent;
use Composer\Script\ScriptEvents;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
@@ -50,6 +51,7 @@ protected function configure()
->setDefinition(array(
new InputArgument('script', InputArgument::OPTIONAL, 'Script name to run.'),
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('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),
new InputOption('list', 'l', InputOption::VALUE_NONE, 'List scripts.'),
@@ -86,6 +88,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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);
}

0 comments on commit 93501a5

Please sign in to comment.
You can’t perform that action at this time.