ScriptAliasCommand.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Input\InputArgument;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. /**
  17. * @author Jordi Boggiano <j.boggiano@seld.be>
  18. */
  19. class ScriptAliasCommand extends BaseCommand
  20. {
  21. private $script;
  22. public function __construct($script)
  23. {
  24. $this->script = $script;
  25. parent::__construct();
  26. }
  27. protected function configure()
  28. {
  29. $this
  30. ->setName($this->script)
  31. ->setDescription('Run the '.$this->script.' script as defined in composer.json.')
  32. ->setDefinition(array(
  33. new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
  34. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),
  35. new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
  36. ))
  37. ->setHelp(<<<EOT
  38. The <info>run-script</info> command runs scripts defined in composer.json:
  39. <info>php composer.phar run-script post-update-cmd</info>
  40. EOT
  41. )
  42. ;
  43. }
  44. protected function execute(InputInterface $input, OutputInterface $output)
  45. {
  46. $composer = $this->getComposer();
  47. $args = $input->getArguments();
  48. return $composer->getEventDispatcher()->dispatchScript($this->script, $input->getOption('dev') || !$input->getOption('no-dev'), $args['args']);
  49. }
  50. }