Hello.php 822 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace app\demo\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\input\Argument;
  6. use think\console\input\Option;
  7. use think\console\Output;
  8. class Hello extends Command
  9. {
  10. protected function configure()
  11. {
  12. $this->setName('demo:hello')
  13. ->addArgument('name', Argument::OPTIONAL, "your name")
  14. ->addOption('city', '-c', Option::VALUE_REQUIRED, 'city name')
  15. ->setDescription('Say App Hello');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. $name = trim($input->getArgument('name'));
  20. $city = $input->getOption('city');
  21. $city = $city ? $city : 'China';
  22. $name = $name ? $name : 'ThinkCMF';
  23. $output->writeln("Hello, My name is " . $name . '! I\'m from ' . $city);
  24. }
  25. }