1
0
Fork 0

Add docs for exec command, refs #4887

pull/4962/head
Jordi Boggiano 2016-02-25 12:21:30 +00:00
parent 934be204a2
commit 35d26db704
2 changed files with 17 additions and 7 deletions

View File

@ -602,6 +602,16 @@ Lists the name, version and license of every package installed. Use
To run [scripts](articles/scripts.md) manually you can use this command, To run [scripts](articles/scripts.md) manually you can use this command,
just give it the script name and optionally any required arguments. just give it the script name and optionally any required arguments.
## exec
Executes a vendored binary/script. You can execute any command and this will
ensure that the Composer bin-dir is pushed on your PATH before the command
runs.
### Options
* **--list:** List the available composer binaries
## diagnose ## diagnose
If you think you found a bug, or something is behaving strangely, you might If you think you found a bug, or something is behaving strangely, you might

View File

@ -29,11 +29,11 @@ class ExecCommand extends BaseCommand
->setDescription('Execute a vendored binary/script') ->setDescription('Execute a vendored binary/script')
->setDefinition(array( ->setDefinition(array(
new InputOption('list', 'l', InputOption::VALUE_NONE), new InputOption('list', 'l', InputOption::VALUE_NONE),
new InputArgument('script', InputArgument::OPTIONAL, 'The script to run, e.g. phpunit'), new InputArgument('binary', InputArgument::OPTIONAL, 'The binary to run, e.g. phpunit'),
new InputArgument( new InputArgument(
'args', 'args',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL, InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
'Arguments to pass to the script. Use <info>--</info> to separate from composer arguments' 'Arguments to pass to the binary. Use <info>--</info> to separate from composer arguments'
), ),
)) ))
; ;
@ -43,15 +43,15 @@ class ExecCommand extends BaseCommand
{ {
$composer = $this->getComposer(); $composer = $this->getComposer();
$binDir = $composer->getConfig()->get('bin-dir'); $binDir = $composer->getConfig()->get('bin-dir');
if ($input->getOption('list') || !$input->getArgument('script')) { if ($input->getOption('list') || !$input->getArgument('binary')) {
$bins = glob($binDir . '/*'); $bins = glob($binDir . '/*');
if (!$bins) { if (!$bins) {
throw new \RuntimeException("No scripts found in bin-dir ($binDir)"); throw new \RuntimeException("No binaries found in bin-dir ($binDir)");
} }
$this->getIO()->write(<<<EOT $this->getIO()->write(<<<EOT
<comment>Available scripts:</comment> <comment>Available binaries:</comment>
EOT EOT
); );
@ -72,10 +72,10 @@ EOT
return; return;
} }
$script = $input->getArgument('script'); $binary = $input->getArgument('binary');
$dispatcher = $composer->getEventDispatcher(); $dispatcher = $composer->getEventDispatcher();
$dispatcher->addListener('__exec_command', $script); $dispatcher->addListener('__exec_command', $binary);
if ($output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) { if ($output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET); $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
} }