1: <?php
2:
3: App::uses('Shell', 'Console');
4: App::uses('PluginManager', 'PluginManager.Lib');
5:
6: class DependencyShell extends Shell {
7:
8: 9: 10: 11: 12:
13: public function getOptionParser() {
14: $parser = parent::getOptionParser();
15: $parser->description('Plugin manager.');
16: $parser->addOptions(
17: array(
18: 'pluginName' => array(
19: 'short' => 'p',
20: 'default' => 'app',
21: 'help' => __d('plugin_manager',"Plugin's name or \"app\".")
22: ),
23: )
24: );
25: $parser->addSubcommands(array(
26: 'tree' => array(
27: 'help' => __d('plugin_manager','Show a dependency tree')
28: ),
29: 'inTree' => array(
30: 'help' => __d('plugin_manager','Show plugins in the tree')
31: ),
32: 'notInTree' => array(
33: 'help' => __d('plugin_manager','Show plugins not in the tree')
34: ),
35: ));
36:
37: return $parser;
38: }
39:
40: public function main() {
41: $this->out($this->getOptionParser()->help());
42: }
43:
44: public function tree() {
45: $this->_pluginDependencies(
46: PluginManager::plugin($this->params['pluginName'])
47: , 0);
48: }
49:
50: private function _pluginDependencies(Plugin $plugin, $level) {
51: $this->out(str_repeat(' ', $level * 2) . '- ' . $plugin->getName());
52:
53: foreach ($plugin->dependencies() as $dependencyName) {
54: $this->_pluginDependencies(PluginManager::plugin($dependencyName), $level + 1);
55: }
56: }
57:
58: public function inTree() {
59: foreach(PluginManager::inTree($this->params['pluginName']) as $plugin) {
60: $this->out($plugin);
61: }
62: }
63:
64: public function notInTree() {
65: foreach(PluginManager::notInTree($this->params['pluginName']) as $plugin) {
66: $this->out($plugin);
67: }
68: }
69:
70: }