ScriptAliasCommand.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. private $description;
  23. public function __construct($script, $description)
  24. {
  25. $this->script = $script;
  26. $this->description = empty($description) ? 'Runs the '.$script.' script as defined in composer.json.' : $description;
  27. parent::__construct();
  28. }
  29. protected function configure()
  30. {
  31. $this
  32. ->setName($this->script)
  33. ->setDescription($this->description)
  34. ->setDefinition(array(
  35. new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
  36. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),
  37. new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
  38. ))
  39. ->setHelp(<<<EOT
  40. The <info>run-script</info> command runs scripts defined in composer.json:
  41. <info>php composer.phar run-script post-update-cmd</info>
  42. EOT
  43. )
  44. ;
  45. }
  46. protected function execute(InputInterface $input, OutputInterface $output)
  47. {
  48. $composer = $this->getComposer();
  49. $args = $input->getArguments();
  50. return $composer->getEventDispatcher()->dispatchScript($this->script, $input->getOption('dev') || !$input->getOption('no-dev'), $args['args']);
  51. }
  52. }