使用命令参数
参数是位于命令名称之后的字符串,以空格分隔。它们是有序的,可以是可选的,也可以是必需的。例如,要向last_name
命令添加可选参数并将其设置name
为必需参数:
// ...
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
class GreetCommand extends Command
{
// ...
protected function configure(): void
{
$this
// ...
->addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?')
->addArgument('last_name', InputArgument::OPTIONAL, 'Your last name?')
;
}
}
您现在可以访问last_name
命令中的参数: