【发布时间】:2016-11-14 18:21:18
【问题描述】:
我正在尝试编写一个 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')
);
}
有什么想法吗?
【问题讨论】:
-
按照@Kjell 的建议,自己验证选项。就像你说的,选项是可选的。
标签: php laravel-5 laravel-artisan