params['xml'])) { parent::startup(); } } /** * Main function Prints out the list of shells. * * @return void */ public function main() { if (empty($this->params['xml'])) { $this->out("Current Paths:", 2); $this->out("* app: " . APP_DIR); $this->out("* root: " . rtrim(ROOT, DIRECTORY_SEPARATOR)); $this->out("* core: " . rtrim(CORE_PATH, DIRECTORY_SEPARATOR)); $this->out(""); $this->out("Available Shells:", 2); } $shellList = $this->Command->getShellList(); if (empty($shellList)) { return; } if (empty($this->params['xml'])) { $this->_asText($shellList); } else { $this->_asXml($shellList); } } /** * Output text. * * @param array $shellList The shell list. * @return void */ protected function _asText($shellList) { foreach ($shellList as $plugin => $commands) { sort($commands); $this->out(sprintf('[%s] %s', $plugin, implode(', ', $commands))); $this->out(); } $this->out("To run an app or core command, type `cake shell_name [args]`"); $this->out("To run a plugin command, type `cake Plugin.shell_name [args]`"); $this->out("To get help on a specific command, type `cake shell_name --help`", 2); } /** * Output as XML * * @param array $shellList The shell list. * @return void */ protected function _asXml($shellList) { $plugins = Plugin::loaded(); $shells = new SimpleXmlElement(''); 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'); } } $this->_io->outputAs(ConsoleOutput::RAW); $this->out($shells->saveXml()); } /** * Gets the option parser instance and configures it. * * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser() { $parser = parent::getOptionParser(); $parser->description( 'Get the list of available shells for this CakePHP application.' )->addOption('xml', [ 'help' => 'Get the listing as XML.', 'boolean' => true ]); return $parser; } }