【发布时间】:2017-10-19 12:52:58
【问题描述】:
很清楚如何在 Laravel 中为 CLI 创建一个简单的命令,这也适用于创建参数,但我似乎找不到关于如何为 CLI 创建选项的简单文档。
我想这样做,以便用户可以在参数之后添加选项。 比如:
php artisan cmd 参数 -a
php artisan cmd 参数 -a -c -x
如何在下面的类中实现这样的结构?
更新代码 确实有一些可能的解决方案。其实很简单。
class cmd extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cmd {argument}
{--s : description}
{--x : description}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$var = $this->argument('argument');
$options = $this->options();
new Main($var,$options);
}
}
【问题讨论】: