我正在尝试编写一个laravel命令,但我无法选择强制执行。
我明白选项的概念是"可选"但是我希望有一个命令可以清楚地输入您正在插入的输入,而且没有特定的顺序。
即。 我想实现这一点,par2和par 2必须
$command-abc --par1=value1 --par2=value2
而不是:
$command-abc value1 value2
到目前为止,这是我使用的签名:
protected $signature = 'dst-comparison:analyse
{--client : Client Name}
{--clientId : Client ID}
{--recordingId : Client Recording ID}
{--CSVFile : Path to the downloaded CSV file from Spotify analytics}
{--dataUpdateTo=null : CSV Data will be truncated from this date onwards}';
按照Laravel文档(https://laravel.com/docs/5.1/artisan)和本指南:http://code.tutsplus.com/tutorials/your-one-stop-guide-to-laravel-commands--net-30349,覆盖getOptions方法似乎正在伎俩,但它对我不起作用。
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('client', null, InputOption::VALUE_REQUIRED, 'Client Name'),
array('clientId', null, InputOption::VALUE_REQUIRED, 'Client ID'),
array('recordingId', null, InputOption::VALUE_REQUIRED, 'Client Recording ID'),
array('CSVFile', null, InputOption::VALUE_REQUIRED, 'Path to the downloaded CSV file from Spotify analytics'),
array('dataUpdateTo', null, InputOption::VALUE_OPTIONAL, 'CSV Data will be truncated from this date onwards')
);
}
有什么想法吗?
答案 0 :(得分:2)
我认为您必须自己处理强制性输入。查看各种输出函数$this->error(...)
并检查是否所有必要的输入都是$this->option('client');
(如果没有定义输入,则返回null
)