<?php
namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\Request;
use think\Db;

class Test extends Command{ //继承think\console\Command
/**
* 重写configure
* {@inheritdoc}
*/
protected function configure()
{

    //设置参数
    $this->addArgument('email', Argument::REQUIRED); //必传参数
    $this->addArgument('mobile', Argument::OPTIONAL);//可选参数


    //选项定义
    $this->addOption('page', 'm', Option::VALUE_REQUIRED, 'test');//选项值必填
    $this->addOption('status', 's', Option::VALUE_OPTIONAL, 'test'); //选项值选填

 

    $this->setName('test')
    ->setDescription('执行定时!');
}


/**
* 重写execute
* {@inheritdoc}
*/
protected function execute(Input $input, Output $output)
{

  //获取参数值
  $args = $input->getArguments();
  $output->writeln('The args value is:');
  print_r($args);
  $options = $input->getOptions();
  $output->writeln('The options value is:');
  echo $options['page'];

  $output->writeln('执行成功');
}

}

相关文章:

  • 2021-06-14
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2021-12-14
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-01-20
相关资源
相似解决方案