PageRenderTime 71ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/drush/composer/vendor/composer/composer/src/Composer/Command/ExecCommand.php

https://bitbucket.org/kbasarab/kbasarab_vim
PHP | 85 lines | 59 code | 13 blank | 13 comment | 6 complexity | 7a1c5da76984f3f04f992b09e59470ba MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Command;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\Console\Input\InputArgument;
  16. /**
  17. * @author Davey Shafik <me@daveyshafik.com>
  18. */
  19. class ExecCommand extends BaseCommand
  20. {
  21. protected function configure()
  22. {
  23. $this
  24. ->setName('exec')
  25. ->setDescription('Execute a vendored binary/script')
  26. ->setDefinition(array(
  27. new InputOption('list', 'l', InputOption::VALUE_NONE),
  28. new InputArgument('binary', InputArgument::OPTIONAL, 'The binary to run, e.g. phpunit'),
  29. new InputArgument(
  30. 'args',
  31. InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
  32. 'Arguments to pass to the binary. Use <info>--</info> to separate from composer arguments'
  33. ),
  34. ))
  35. ;
  36. }
  37. protected function execute(InputInterface $input, OutputInterface $output)
  38. {
  39. $composer = $this->getComposer();
  40. $binDir = $composer->getConfig()->get('bin-dir');
  41. if ($input->getOption('list') || !$input->getArgument('binary')) {
  42. $bins = glob($binDir . '/*');
  43. if (!$bins) {
  44. throw new \RuntimeException("No binaries found in bin-dir ($binDir)");
  45. }
  46. $this->getIO()->write(<<<EOT
  47. <comment>Available binaries:</comment>
  48. EOT
  49. );
  50. foreach ($bins as $bin) {
  51. // skip .bat copies
  52. if (isset($previousBin) && $bin === $previousBin.'.bat') {
  53. continue;
  54. }
  55. $previousBin = $bin;
  56. $bin = basename($bin);
  57. $this->getIO()->write(<<<EOT
  58. <info>- $bin</info>
  59. EOT
  60. );
  61. }
  62. return;
  63. }
  64. $binary = $input->getArgument('binary');
  65. $dispatcher = $composer->getEventDispatcher();
  66. $dispatcher->addListener('__exec_command', $binary);
  67. if ($output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
  68. $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
  69. }
  70. return $dispatcher->dispatchScript('__exec_command', true, $input->getArgument('args'));
  71. }
  72. }