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
|
|
|
|
2013-09-28 15:42:28 +00:00
|
|
|
/**
|
|
|
|
* Contains tasks to load and instantiate
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $tasks = array('Command');
|
|
|
|
|
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));
|
2016-11-08 09:03:46 +00:00
|
|
|
$this->out(" -webroot: " . rtrim(WWW_ROOT, DS));
|
2010-10-20 03:25:23 +00:00
|
|
|
$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
|
|
|
|
2013-09-28 15:42:28 +00:00
|
|
|
$shellList = $this->Command->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output text.
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param array $shellList The shell list.
|
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
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param array $shellList The shell list.
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-05 23:38:32 +00:00
|
|
|
* Gets the option parser instance and configures it.
|
2010-10-20 03:21:24 +00:00
|
|
|
*
|
2013-12-05 23:38:32 +00:00
|
|
|
* @return ConsoleOptionParser
|
2010-10-20 03:21:24 +00:00
|
|
|
*/
|
|
|
|
public function getOptionParser() {
|
|
|
|
$parser = parent::getOptionParser();
|
2013-12-05 23:38:32 +00:00
|
|
|
|
|
|
|
$parser->description(
|
|
|
|
__d('cake_console', 'Get the list of available shells for this CakePHP application.')
|
|
|
|
)->addOption('sort', array(
|
|
|
|
'help' => __d('cake_console', 'Does nothing (deprecated)'),
|
|
|
|
'boolean' => true
|
|
|
|
))->addOption('xml', array(
|
|
|
|
'help' => __d('cake_console', 'Get the listing as XML.'),
|
|
|
|
'boolean' => true
|
|
|
|
));
|
|
|
|
|
|
|
|
return $parser;
|
2010-10-20 03:21:24 +00:00
|
|
|
}
|
2012-03-03 23:55:07 +00:00
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|