- 第一步:还是要把自定义的命令配置到command.php里面去。具体操作见tp文档(传送门)
- 第二步: 直接上代码
<?php
namespace app\admin\command;
use think\console\Command;
use think\console\Input;
use think\console\Input\Argument;
use think\console\Input\Option;
use think\console\Output;
class Test extends Command
{
protected function configure()
{
// 命令行参数
$this->addArgument('a', Argument::REQUIRED); // 必须参数
$this->addArgument('b', Argument::REQUIRED);
$this->addArgument('c', Argument::OPTIONAL); // 可选参数
// 添加选项
$this->addOption('type', 't', Option::VALUE_OPTIONAL, 'test'); // 可选选项
//$this->addOption('type', 'q', Option::VALUE_REQUIRED, 'test'); // 必须选项
$this->setName('test');
$this->setDescription('测试一个计算器');
}