Help.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\console\command;
  12. use think\console\Command;
  13. use think\console\Input;
  14. use think\console\input\Argument as InputArgument;
  15. use think\console\input\Option as InputOption;
  16. use think\console\Output;
  17. class Help extends Command
  18. {
  19. private $command;
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function configure()
  24. {
  25. $this->ignoreValidationErrors();
  26. $this->setName('help')->setDefinition([
  27. new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
  28. new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
  29. ])->setDescription('Displays help for a command')->setHelp(<<<EOF
  30. The <info>%command.name%</info> command displays help for a given command:
  31. <info>php %command.full_name% list</info>
  32. To display the list of available commands, please use the <info>list</info> command.
  33. EOF
  34. );
  35. }
  36. /**
  37. * Sets the command.
  38. * @param Command $command The command to set
  39. */
  40. public function setCommand(Command $command)
  41. {
  42. $this->command = $command;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. protected function execute(Input $input, Output $output)
  48. {
  49. if (null === $this->command) {
  50. $this->command = $this->getConsole()->find($input->getArgument('command_name'));
  51. }
  52. $output->describe($this->command, [
  53. 'raw_text' => $input->getOption('raw'),
  54. ]);
  55. $this->command = null;
  56. }
  57. }