2010-10-04 03:42:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2011-07-31 23:14:36 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-10-04 03:42:24 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-04 03:42:24 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-10-04 03:42:24 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-31 23:14:36 +00:00
|
|
|
* @package Cake.Console.Command
|
2010-10-04 03:42:24 +00:00
|
|
|
* @since CakePHP v 2.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-10-04 03:42:24 +00:00
|
|
|
*/
|
|
|
|
|
2011-11-25 21:05:00 +00:00
|
|
|
App::uses('AppShell', 'Console/Command');
|
2011-03-08 18:45:44 +00:00
|
|
|
App::uses('Inflector', 'Utility');
|
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
/**
|
|
|
|
* Shows a list of commands available from the console.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Console.Command
|
2010-10-04 03:42:24 +00:00
|
|
|
*/
|
2011-11-25 21:05:00 +00:00
|
|
|
class CommandListShell extends AppShell {
|
2010-10-20 03:25:23 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-20 03:25:42 +00:00
|
|
|
* startup
|
2010-10-20 03:25:23 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function startup() {
|
|
|
|
if (empty($this->params['xml'])) {
|
|
|
|
parent::startup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
/**
|
|
|
|
* Main function Prints out the list of shells.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function main() {
|
2010-10-20 03:25:23 +00:00
|
|
|
if (empty($this->params['xml'])) {
|
2011-04-25 19:17:59 +00:00
|
|
|
$this->out(__d('cake_console', "<info>Current Paths:</info>"), 2);
|
2012-03-03 23:55:07 +00:00
|
|
|
$this->out(" -app: " . APP_DIR);
|
2011-07-31 18:49:33 +00:00
|
|
|
$this->out(" -working: " . rtrim(APP, DS));
|
2010-10-24 19:11:30 +00:00
|
|
|
$this->out(" -root: " . rtrim(ROOT, DS));
|
2010-10-20 03:25:23 +00:00
|
|
|
$this->out(" -core: " . rtrim(CORE_PATH, DS));
|
|
|
|
$this->out("");
|
2011-04-25 19:17:59 +00:00
|
|
|
$this->out(__d('cake_console', "<info>Changing Paths:</info>"), 2);
|
2013-05-09 07:22:43 +00:00
|
|
|
$this->out(__d('cake_console', "Your working path should be the same as your application path. To change your path use the '-app' param."));
|
2013-05-22 09:15:01 +00:00
|
|
|
$this->out(__d('cake_console', "Example: %s or %s", '-app relative/path/to/myapp', '-app /absolute/path/to/myapp'), 2);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2011-04-25 19:17:59 +00:00
|
|
|
$this->out(__d('cake_console', "<info>Available Shells:</info>"), 2);
|
2010-10-20 03:25:23 +00:00
|
|
|
}
|
2010-10-20 03:21:24 +00:00
|
|
|
|
|
|
|
$shellList = $this->_getShellList();
|
2012-06-18 20:47:01 +00:00
|
|
|
if (empty($shellList)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-10-20 03:21:24 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
if (empty($this->params['xml'])) {
|
|
|
|
$this->_asText($shellList);
|
|
|
|
} else {
|
|
|
|
$this->_asXml($shellList);
|
2010-10-20 03:21:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the shell command listing.
|
|
|
|
*
|
2011-08-16 03:55:08 +00:00
|
|
|
* @return array
|
2010-10-20 03:21:24 +00:00
|
|
|
*/
|
|
|
|
protected function _getShellList() {
|
2011-11-25 21:05:00 +00:00
|
|
|
$skipFiles = array('AppShell');
|
2010-10-17 21:32:37 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
$plugins = CakePlugin::loaded();
|
|
|
|
$shellList = array_fill_keys($plugins, null) + array('CORE' => null, 'app' => null);
|
|
|
|
|
2011-11-13 01:43:55 +00:00
|
|
|
$corePath = App::core('Console/Command');
|
|
|
|
$shells = App::objects('file', $corePath[0]);
|
2011-11-25 21:05:00 +00:00
|
|
|
$shells = array_diff($shells, $skipFiles);
|
2012-06-18 20:47:01 +00:00
|
|
|
$this->_appendShells('CORE', $shells, $shellList);
|
2010-10-17 21:32:37 +00:00
|
|
|
|
2011-03-08 18:45:44 +00:00
|
|
|
$appShells = App::objects('Console/Command', null, false);
|
2011-11-25 21:05:00 +00:00
|
|
|
$appShells = array_diff($appShells, $shells, $skipFiles);
|
2012-06-18 20:47:01 +00:00
|
|
|
$this->_appendShells('app', $appShells, $shellList);
|
2010-10-17 21:32:37 +00:00
|
|
|
|
|
|
|
foreach ($plugins as $plugin) {
|
2011-03-08 18:45:44 +00:00
|
|
|
$pluginShells = App::objects($plugin . '.Console/Command');
|
2012-06-18 20:47:01 +00:00
|
|
|
$this->_appendShells($plugin, $pluginShells, $shellList);
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|
2011-03-08 18:45:44 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
return array_filter($shellList);
|
2010-10-17 21:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scan the provided paths for shells, and append them into $shellList
|
|
|
|
*
|
2011-07-29 02:03:44 +00:00
|
|
|
* @param string $type
|
|
|
|
* @param array $shells
|
|
|
|
* @param array $shellList
|
2012-11-28 22:30:47 +00:00
|
|
|
* @return void
|
2010-10-17 21:32:37 +00:00
|
|
|
*/
|
2012-06-18 20:47:01 +00:00
|
|
|
protected function _appendShells($type, $shells, &$shellList) {
|
2011-03-08 18:45:44 +00:00
|
|
|
foreach ($shells as $shell) {
|
2012-06-18 20:47:01 +00:00
|
|
|
$shellList[$type][] = Inflector::underscore(str_replace('Shell', '', $shell));
|
2010-10-17 21:32:37 +00:00
|
|
|
}
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|
2010-10-20 03:21:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Output text.
|
|
|
|
*
|
2011-07-29 02:03:44 +00:00
|
|
|
* @param array $shellList
|
2010-10-20 03:21:24 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _asText($shellList) {
|
2012-06-18 20:47:01 +00:00
|
|
|
foreach ($shellList as $plugin => $commands) {
|
|
|
|
sort($commands);
|
|
|
|
$this->out(sprintf('[<info>%s</info>] %s', $plugin, implode(', ', $commands)));
|
|
|
|
$this->out();
|
2010-10-20 03:21:24 +00:00
|
|
|
}
|
|
|
|
|
2011-10-20 01:26:04 +00:00
|
|
|
$this->out(__d('cake_console', "To run an app or core command, type <info>cake shell_name [args]</info>"));
|
|
|
|
$this->out(__d('cake_console', "To run a plugin command, type <info>cake Plugin.shell_name [args]</info>"));
|
2011-04-25 19:17:59 +00:00
|
|
|
$this->out(__d('cake_console', "To get help on a specific command, type <info>cake shell_name --help</info>"), 2);
|
2010-10-20 03:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output as XML
|
|
|
|
*
|
2011-07-29 02:03:44 +00:00
|
|
|
* @param array $shellList
|
2010-10-20 03:21:24 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _asXml($shellList) {
|
2011-05-12 04:50:29 +00:00
|
|
|
$plugins = CakePlugin::loaded();
|
2010-10-20 03:21:24 +00:00
|
|
|
$shells = new SimpleXmlElement('<shells></shells>');
|
2012-06-18 20:47:01 +00:00
|
|
|
foreach ($shellList as $plugin => $commands) {
|
|
|
|
foreach ($commands as $command) {
|
|
|
|
$callable = $command;
|
|
|
|
if (in_array($plugin, $plugins)) {
|
|
|
|
$callable = Inflector::camelize($plugin) . '.' . $command;
|
|
|
|
}
|
|
|
|
|
|
|
|
$shell = $shells->addChild('shell');
|
|
|
|
$shell->addAttribute('name', $command);
|
|
|
|
$shell->addAttribute('call_as', $callable);
|
|
|
|
$shell->addAttribute('provider', $plugin);
|
|
|
|
$shell->addAttribute('help', $callable . ' -h');
|
2010-10-20 03:21:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-21 16:44:36 +00:00
|
|
|
$this->stdout->outputAs(ConsoleOutput::RAW);
|
2010-10-20 03:21:24 +00:00
|
|
|
$this->out($shells->saveXml());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the option parser
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function getOptionParser() {
|
|
|
|
$parser = parent::getOptionParser();
|
2011-04-25 19:17:59 +00:00
|
|
|
return $parser->description(__d('cake_console', 'Get the list of available shells for this CakePHP application.'))
|
2012-06-23 00:53:09 +00:00
|
|
|
->addOption('sort', array(
|
|
|
|
'help' => __d('cake_console', 'Does nothing (deprecated)'),
|
|
|
|
'boolean' => true
|
|
|
|
))
|
2010-10-20 03:21:24 +00:00
|
|
|
->addOption('xml', array(
|
2011-03-19 17:32:35 +00:00
|
|
|
'help' => __d('cake_console', 'Get the listing as XML.'),
|
2010-10-20 03:21:24 +00:00
|
|
|
'boolean' => true
|
|
|
|
));
|
|
|
|
}
|
2012-03-03 23:55:07 +00:00
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|