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(" -webroot: " . rtrim(WWW_ROOT, DS));
58: $this->out("");
59: $this->out(__d('cake_console', "<info>Changing Paths:</info>"), 2);
60: $this->out(__d('cake_console', "Your working path should be the same as your application path. To change your path use the '-app' param."));
61: $this->out(__d('cake_console', "Example: %s or %s", '-app relative/path/to/myapp', '-app /absolute/path/to/myapp'), 2);
62:
63: $this->out(__d('cake_console', "<info>Available Shells:</info>"), 2);
64: }
65:
66: $shellList = $this->Command->getShellList();
67: if (empty($shellList)) {
68: return;
69: }
70:
71: if (empty($this->params['xml'])) {
72: $this->_asText($shellList);
73: } else {
74: $this->_asXml($shellList);
75: }
76: }
77:
78: 79: 80: 81: 82: 83:
84: protected function _asText($shellList) {
85: foreach ($shellList as $plugin => $commands) {
86: sort($commands);
87: $this->out(sprintf('[<info>%s</info>] %s', $plugin, implode(', ', $commands)));
88: $this->out();
89: }
90:
91: $this->out(__d('cake_console', "To run an app or core command, type <info>cake shell_name [args]</info>"));
92: $this->out(__d('cake_console', "To run a plugin command, type <info>cake Plugin.shell_name [args]</info>"));
93: $this->out(__d('cake_console', "To get help on a specific command, type <info>cake shell_name --help</info>"), 2);
94: }
95:
96: 97: 98: 99: 100: 101:
102: protected function _asXml($shellList) {
103: $plugins = CakePlugin::loaded();
104: $shells = new SimpleXmlElement('<shells></shells>');
105: foreach ($shellList as $plugin => $commands) {
106: foreach ($commands as $command) {
107: $callable = $command;
108: if (in_array($plugin, $plugins)) {
109: $callable = Inflector::camelize($plugin) . '.' . $command;
110: }
111:
112: $shell = $shells->addChild('shell');
113: $shell->addAttribute('name', $command);
114: $shell->addAttribute('call_as', $callable);
115: $shell->addAttribute('provider', $plugin);
116: $shell->addAttribute('help', $callable . ' -h');
117: }
118: }
119: $this->stdout->outputAs(ConsoleOutput::RAW);
120: $this->out($shells->saveXml());
121: }
122:
123: 124: 125: 126: 127:
128: public function getOptionParser() {
129: $parser = parent::getOptionParser();
130:
131: $parser->description(
132: __d('cake_console', 'Get the list of available shells for this CakePHP application.')
133: )->addOption('sort', array(
134: 'help' => __d('cake_console', 'Does nothing (deprecated)'),
135: 'boolean' => true
136: ))->addOption('xml', array(
137: 'help' => __d('cake_console', 'Get the listing as XML.'),
138: 'boolean' => true
139: ));
140:
141: return $parser;
142: }
143:
144: }
145: