pictcode / lib / Cake / Console / Command / CommandListShell.php @ fbcf274f
履歴 | 表示 | アノテート | ダウンロード (3.986 KB)
| 1 | 635eef61 | spyder1211 | <?php
|
|---|---|---|---|
| 2 | /**
|
||
| 3 | * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||
| 4 | * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
| 5 | *
|
||
| 6 | * Licensed under The MIT License
|
||
| 7 | * For full copyright and license information, please see the LICENSE.txt
|
||
| 8 | * Redistributions of files must retain the above copyright notice.
|
||
| 9 | *
|
||
| 10 | * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
| 11 | * @link http://cakephp.org CakePHP Project
|
||
| 12 | * @package Cake.Console.Command
|
||
| 13 | * @since CakePHP v 2.0
|
||
| 14 | * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||
| 15 | */
|
||
| 16 | |||
| 17 | App::uses('AppShell', 'Console/Command'); |
||
| 18 | App::uses('Inflector', 'Utility'); |
||
| 19 | |||
| 20 | /**
|
||
| 21 | * Shows a list of commands available from the console.
|
||
| 22 | *
|
||
| 23 | * @package Cake.Console.Command
|
||
| 24 | */
|
||
| 25 | class CommandListShell extends AppShell { |
||
| 26 | |||
| 27 | /**
|
||
| 28 | * Contains tasks to load and instantiate
|
||
| 29 | *
|
||
| 30 | * @var array
|
||
| 31 | */
|
||
| 32 | public $tasks = array('Command'); |
||
| 33 | |||
| 34 | /**
|
||
| 35 | * startup
|
||
| 36 | *
|
||
| 37 | * @return void
|
||
| 38 | */
|
||
| 39 | public function startup() { |
||
| 40 | if (empty($this->params['xml'])) { |
||
| 41 | parent::startup();
|
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | /**
|
||
| 46 | * Main function Prints out the list of shells.
|
||
| 47 | *
|
||
| 48 | * @return void
|
||
| 49 | */
|
||
| 50 | public function main() { |
||
| 51 | if (empty($this->params['xml'])) { |
||
| 52 | $this->out(__d('cake_console', "<info>Current Paths:</info>"), 2); |
||
| 53 | $this->out(" -app: " . APP_DIR); |
||
| 54 | $this->out(" -working: " . rtrim(APP, DS)); |
||
| 55 | $this->out(" -root: " . rtrim(ROOT, DS)); |
||
| 56 | $this->out(" -core: " . rtrim(CORE_PATH, DS)); |
||
| 57 | $this->out(""); |
||
| 58 | $this->out(__d('cake_console', "<info>Changing Paths:</info>"), 2); |
||
| 59 | $this->out(__d('cake_console', "Your working path should be the same as your application path. To change your path use the '-app' param.")); |
||
| 60 | $this->out(__d('cake_console', "Example: %s or %s", '-app relative/path/to/myapp', '-app /absolute/path/to/myapp'), 2); |
||
| 61 | |||
| 62 | $this->out(__d('cake_console', "<info>Available Shells:</info>"), 2); |
||
| 63 | } |
||
| 64 | |||
| 65 | $shellList = $this->Command->getShellList(); |
||
| 66 | if (empty($shellList)) { |
||
| 67 | return;
|
||
| 68 | } |
||
| 69 | |||
| 70 | if (empty($this->params['xml'])) { |
||
| 71 | $this->_asText($shellList); |
||
| 72 | } else {
|
||
| 73 | $this->_asXml($shellList); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | /**
|
||
| 78 | * Output text.
|
||
| 79 | *
|
||
| 80 | * @param array $shellList The shell list.
|
||
| 81 | * @return void
|
||
| 82 | */
|
||
| 83 | protected function _asText($shellList) { |
||
| 84 | foreach ($shellList as $plugin => $commands) { |
||
| 85 | sort($commands); |
||
| 86 | $this->out(sprintf('[<info>%s</info>] %s', $plugin, implode(', ', $commands))); |
||
| 87 | $this->out();
|
||
| 88 | } |
||
| 89 | |||
| 90 | $this->out(__d('cake_console', "To run an app or core command, type <info>cake shell_name [args]</info>")); |
||
| 91 | $this->out(__d('cake_console', "To run a plugin command, type <info>cake Plugin.shell_name [args]</info>")); |
||
| 92 | $this->out(__d('cake_console', "To get help on a specific command, type <info>cake shell_name --help</info>"), 2); |
||
| 93 | } |
||
| 94 | |||
| 95 | /**
|
||
| 96 | * Output as XML
|
||
| 97 | *
|
||
| 98 | * @param array $shellList The shell list.
|
||
| 99 | * @return void
|
||
| 100 | */
|
||
| 101 | protected function _asXml($shellList) { |
||
| 102 | $plugins = CakePlugin::loaded(); |
||
| 103 | $shells = new SimpleXmlElement('<shells></shells>'); |
||
| 104 | foreach ($shellList as $plugin => $commands) { |
||
| 105 | foreach ($commands as $command) { |
||
| 106 | $callable = $command; |
||
| 107 | if (in_array($plugin, $plugins)) { |
||
| 108 | $callable = Inflector::camelize($plugin) . '.' . $command; |
||
| 109 | } |
||
| 110 | |||
| 111 | $shell = $shells->addChild('shell'); |
||
| 112 | $shell->addAttribute('name', $command); |
||
| 113 | $shell->addAttribute('call_as', $callable); |
||
| 114 | $shell->addAttribute('provider', $plugin); |
||
| 115 | $shell->addAttribute('help', $callable . ' -h'); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | $this->stdout->outputAs(ConsoleOutput::RAW); |
||
| 119 | $this->out($shells->saveXml()); |
||
| 120 | } |
||
| 121 | |||
| 122 | /**
|
||
| 123 | * Gets the option parser instance and configures it.
|
||
| 124 | *
|
||
| 125 | * @return ConsoleOptionParser
|
||
| 126 | */
|
||
| 127 | public function getOptionParser() { |
||
| 128 | $parser = parent::getOptionParser(); |
||
| 129 | |||
| 130 | $parser->description(
|
||
| 131 | __d('cake_console', 'Get the list of available shells for this CakePHP application.') |
||
| 132 | )->addOption('sort', array( |
||
| 133 | 'help' => __d('cake_console', 'Does nothing (deprecated)'), |
||
| 134 | 'boolean' => true |
||
| 135 | ))->addOption('xml', array( |
||
| 136 | 'help' => __d('cake_console', 'Get the listing as XML.'), |
||
| 137 | 'boolean' => true |
||
| 138 | )); |
||
| 139 | |||
| 140 | return $parser; |
||
| 141 | } |
||
| 142 | |||
| 143 | } |