1 | <?php |
||
12 | class CommandAdapter extends SymfonyCommand |
||
13 | { |
||
14 | /** @var \Wandu\Console\Command */ |
||
15 | protected $command; |
||
16 | |||
17 | /** |
||
18 | * @param \Wandu\Console\Command $command |
||
19 | */ |
||
20 | public function __construct(Command $command) |
||
21 | { |
||
22 | parent::__construct('_'); |
||
23 | $this->command = $command; |
||
24 | |||
25 | $this->setDescription($command->getDescription()); |
||
26 | $this->setHelp($command->getHelp()); |
||
27 | |||
28 | // arguments |
||
29 | foreach ($command->getArguments() as $argument => $description) { |
||
30 | if (substr($argument, -1) === '?') { |
||
31 | $this->addArgument(substr($argument, 0, -1), InputArgument::OPTIONAL, $description); |
||
32 | } elseif (substr($argument, -2) === '[]') { |
||
33 | $this->addArgument(substr($argument, 0, -2), InputArgument::IS_ARRAY, $description); |
||
34 | } else { |
||
35 | $this->addArgument($argument, InputArgument::REQUIRED, $description); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | foreach ($command->getOptions() as $option => $description) { |
||
40 | if (substr($option, -1) === '?') { |
||
41 | $this->addOption(substr($option, 0, -1), null, InputOption::VALUE_OPTIONAL, $description); |
||
42 | } elseif (substr($option, -2) === '[]') { |
||
43 | $this->addOption(substr($option, 0, -2), null, InputOption::VALUE_IS_ARRAY, $description); |
||
44 | } else { |
||
45 | $this->addOption($option, null, InputOption::VALUE_REQUIRED, $description); |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
52 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
53 | * @return int |
||
54 | */ |
||
55 | protected function execute(InputInterface $input, OutputInterface $output) |
||
64 | } |
||
65 |