Arguments are the strings - separated by spaces - that
come after the command name itself. They are ordered, and can be optional
or required. For example, to add an optional last_name argument to the command
and make the name argument required:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// ...useSymfony\Component\Console\Input\InputArgument;classGreetCommandextendsCommand{// ...protectedfunctionconfigure(){$this// ...->addArgument('name',InputArgument::REQUIRED,'Who do you want to greet?')->addArgument('last_name',InputArgument::OPTIONAL,'Your last name?');}}

Unlike arguments, options are not ordered (meaning you can specify them in any
order) and are specified with two dashes (e.g. --yell). Options are
always optional, and can be setup to accept a value (e.g. --dir=src) or
simply as a boolean flag without a value (e.g. --yell).

For example, add a new option to the command that can be used to specify
how many times in a row the message should be printed:

1
2
3
4
5
6
7
8
9

$this// ...->addOption('iterations',null,InputOption::VALUE_REQUIRED,'How many times should the message be printed?',1);

You can also declare a one-letter shortcut that you can call with a single
dash, like -i:

1
2
3
4
5
6
7
8
9

$this// ...->addOption('iterations','i',InputOption::VALUE_REQUIRED,'How many times should the message be printed?',1);

There are four option variants you can use:

InputOption::VALUE_IS_ARRAY

This option accepts multiple values (e.g. --dir=/foo --dir=/bar);

InputOption::VALUE_NONE

Do not accept input for this option (e.g. --yell);

InputOption::VALUE_REQUIRED

This value is required (e.g. --iterations=5), the option itself is
still optional;

InputOption::VALUE_OPTIONAL

This option may or may not have a value (e.g. --yell or
--yell=loud).

You can combine VALUE_IS_ARRAY with VALUE_REQUIRED or
VALUE_OPTIONAL like this:

1
2
3
4
5
6
7
8
9

$this// ...->addOption('colors',null,InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY,'Which colors do you like?',array('blue','red'));

Tip

There is nothing forbidding you to create a command with an option that
optionally accepts a value. However, there is no way you can distinguish
when the option was used without a value (command --language) or when
it wasn't used at all (command). In both cases, the value retrieved for
the option will be null.