1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: App::uses('AppShell', 'Console/Command');
18: App::uses('Inflector', 'Utility');
19:
20: 21: 22: 23: 24:
25: class CommandListShell extends AppShell {
26:
27: 28: 29: 30: 31:
32: public $tasks = array('Command');
33:
34: 35: 36: 37: 38:
39: public function startup() {
40: if (empty($this->params['xml'])) {
41: parent::startup();
42: }
43: }
44:
45: 46: 47: 48: 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: 79: 80: 81: 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: 97: 98: 99: 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: 124: 125: 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: }
144: