HelpCommand.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * HelpCommand class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * HelpCommand displays help information for commands under yiic shell.
  12. *
  13. * @property string $help The command description.
  14. *
  15. * @author Qiang Xue <qiang.xue@gmail.com>
  16. * @package system.cli.commands.shell
  17. * @since 1.0
  18. */
  19. class HelpCommand extends CConsoleCommand
  20. {
  21. /**
  22. * Execute the action.
  23. * @param array $args command line parameters specific for this command
  24. * @return integer non zero application exit code for help
  25. */
  26. public function run($args)
  27. {
  28. $runner=$this->getCommandRunner();
  29. $commands=$runner->commands;
  30. if(isset($args[0]))
  31. $name=strtolower($args[0]);
  32. if(!isset($args[0]) || !isset($commands[$name]))
  33. {
  34. echo <<<EOD
  35. At the prompt, you may enter a PHP statement or one of the following commands:
  36. EOD;
  37. $commandNames=array_keys($commands);
  38. sort($commandNames);
  39. echo ' - '.implode("\n - ",$commandNames);
  40. echo <<<EOD
  41. Type 'help <command-name>' for details about a command.
  42. To expand the above command list, place your command class files
  43. under 'protected/commands/shell', or a directory specified
  44. by the 'YIIC_SHELL_COMMAND_PATH' environment variable. The command class
  45. must extend from CConsoleCommand.
  46. EOD;
  47. }
  48. else
  49. echo $runner->createCommand($name)->getHelp();
  50. return 1;
  51. }
  52. /**
  53. * Provides the command description.
  54. * @return string the command description.
  55. */
  56. public function getHelp()
  57. {
  58. return <<<EOD
  59. USAGE
  60. help [command-name]
  61. DESCRIPTION
  62. Display the help information for the specified command.
  63. If the command name is not given, all commands will be listed.
  64. PARAMETERS
  65. * command-name: optional, the name of the command to show help information.
  66. EOD;
  67. }
  68. }