Lists.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Output;
  15. use think\console\input\Argument as InputArgument;
  16. use think\console\input\Option as InputOption;
  17. use think\console\input\Definition as InputDefinition;
  18. class Lists extends Command
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function configure()
  24. {
  25. $this->setName('list')->setDefinition($this->createDefinition())->setDescription('Lists commands')->setHelp(<<<EOF
  26. The <info>%command.name%</info> command lists all commands:
  27. <info>php %command.full_name%</info>
  28. You can also display the commands for a specific namespace:
  29. <info>php %command.full_name% test</info>
  30. It's also possible to get raw list of commands (useful for embedding command runner):
  31. <info>php %command.full_name% --raw</info>
  32. EOF
  33. );
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function getNativeDefinition()
  39. {
  40. return $this->createDefinition();
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. protected function execute(Input $input, Output $output)
  46. {
  47. $output->describe($this->getConsole(), [
  48. 'raw_text' => $input->getOption('raw'),
  49. 'namespace' => $input->getArgument('namespace'),
  50. ]);
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. private function createDefinition()
  56. {
  57. return new InputDefinition([
  58. new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
  59. new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
  60. ]);
  61. }
  62. }