Test.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2020/2/4
  6. * Time: 12:47
  7. */
  8. namespace app\common\command;
  9. use think\console\Command;
  10. use think\console\Input;
  11. use think\console\input\Argument;
  12. use think\console\input\Option;
  13. use think\console\Output;
  14. class Test extends Command
  15. {
  16. /**
  17. * php think test -ab AAA BBB
  18. */
  19. protected function configure()
  20. {
  21. $this->setName('test')
  22. ->addArgument('argsA', Argument::OPTIONAL, "argsA", "argsA")
  23. ->addArgument('argsB', Argument::OPTIONAL, "argsB", "argsB")
  24. ->addArgument('argsC', Argument::OPTIONAL, "argsC", "argsC")
  25. ->addOption('optionA', 'a', Option::VALUE_NONE, 'optionA')
  26. ->addOption('optionB', 'b', Option::VALUE_NONE, 'optionB')
  27. ->addOption('optionC', 'c', Option::VALUE_NONE, 'optionC')
  28. ->setDescription('this is test');
  29. }
  30. protected function execute(Input $input, Output $output)
  31. {
  32. $argsA = $input->getArgument("argsA");
  33. $argsB = $input->getArgument("argsB");
  34. $argsC = $input->getArgument("argsC");
  35. $output->writeln("print args: $argsA $argsB $argsC");
  36. $optionA = $input->getOption("optionA");
  37. $optionB = $input->getOption("optionB");
  38. $optionC = $input->getOption("optionC");
  39. $output->writeln("print options: $optionA , $optionB , $optionC");
  40. }
  41. }