|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ScriptsDev; |
| 4 | + |
| 5 | + |
| 6 | +use Composer\Command\BaseCommand; |
| 7 | +use Symfony\Component\Console\Input\ArrayInput; |
| 8 | +use Symfony\Component\Console\Input\InputArgument; |
| 9 | +use Symfony\Component\Console\Input\InputInterface; |
| 10 | +use Symfony\Component\Console\Input\InputOption; |
| 11 | +use Symfony\Component\Console\Output\OutputInterface; |
| 12 | + |
| 13 | +class DevScriptProxyCommand extends BaseCommand |
| 14 | +{ |
| 15 | + protected function configure() |
| 16 | + { |
| 17 | + $this |
| 18 | + ->setName('{name}') |
| 19 | + ->setDescription('Run the {name} defined in composer.json.') |
| 20 | + ->setDefinition(array( |
| 21 | + new InputArgument('script', InputArgument::OPTIONAL, ''), |
| 22 | + new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''), |
| 23 | + new InputOption('timeout', null, InputOption::VALUE_REQUIRED, |
| 24 | + 'Sets script timeout in seconds, or 0 for never.'), |
| 25 | + new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'), |
| 26 | + new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'), |
| 27 | + new InputOption('list', 'l', InputOption::VALUE_NONE, 'List scripts.'), |
| 28 | + )); |
| 29 | + } |
| 30 | + |
| 31 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 32 | + { |
| 33 | + $args = array( |
| 34 | + 'command' => 'run-script', |
| 35 | + 'script' => $this->getName(), |
| 36 | + 'args' => $input->getArgument('args'), |
| 37 | + '--timeout' => $input->getOption('timeout') ?: '0', |
| 38 | + '--dev' => $input->getOption('dev'), |
| 39 | + '--no-dev' => $input->getOption('no-dev'), |
| 40 | + '--list' => $input->getOption('list'), |
| 41 | + ); |
| 42 | + |
| 43 | + $command = $this->getApplication()->find('run-script'); |
| 44 | + |
| 45 | + $arrayInput = new ArrayInput($args); |
| 46 | + $command->run($arrayInput, $output); |
| 47 | + } |
| 48 | +} |
0 commit comments