4

I am using Symfony's console component, in a command with 1 required option and 1 required argument.

However, upon execution the option and argument are NOT required.

Am I missing something? Relevant code below.

protected function configure()
{
    $this->setName('foo:bar')
         ->setDescription('Some command')
         ->setDefinition(array(
             new InputOption('status', null, InputOption::VALUE_REQUIRED, 'Status to be applied'),
             new InputArgument('ids', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'ids to set status to, space seperated', null)
         ));

}

I expected setDefinition arguments to provide 2 required arguments. This does not seem to be the case.

Stephane Gosselin
  • 9,030
  • 5
  • 42
  • 65
  • I don't know well this one. But this [example](https://symfony.com/doc/current/components/console/console_arguments.html) uses `$this->setDefinition(new InputDefinition(array(new ..., new ...)));` could be ? – Clément Baconnier Sep 06 '18 at 20:03
  • 10
    Options are always optional, you can only specify if the option requires a value or not. An example for an option without a value is `-vvv` or `--help` that are provided by default. As to why the argument does not work, that's odd. have you tried outputting the value? Maybe the `IS_ARRAY` makes it assume it's an empty list instead of null? – dbrumann Sep 06 '18 at 20:07
  • @dbrumann - Aaaah! That makes sense, too! Thanks mate. – Stephane Gosselin Sep 07 '18 at 13:23

0 Answers0