1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: App::uses('AppShell', 'Console/Command');
18:
19: 20: 21: 22: 23:
24: class CompletionShell extends AppShell {
25:
26: 27: 28: 29: 30:
31: public $tasks = array('Command');
32:
33: 34: 35: 36: 37:
38: public function startup() {
39: }
40:
41: 42: 43: 44: 45:
46: public function main() {
47: return $this->out($this->getOptionParser()->help());
48: }
49:
50: 51: 52: 53: 54:
55: public function commands() {
56: $options = $this->Command->commands();
57: return $this->_output($options);
58: }
59:
60: 61: 62: 63: 64:
65: public function options() {
66: $commandName = '';
67: if (!empty($this->args[0])) {
68: $commandName = $this->args[0];
69: }
70: $options = $this->Command->options($commandName);
71:
72: return $this->_output($options);
73: }
74:
75: 76: 77: 78: 79:
80: public function subCommands() {
81: if (!$this->args) {
82: return $this->_output();
83: }
84:
85: $options = $this->Command->subCommands($this->args[0]);
86: return $this->_output($options);
87: }
88:
89: 90: 91: 92: 93:
94: public function fuzzy() {
95: return $this->_output();
96: }
97:
98: 99: 100: 101: 102:
103: public function getOptionParser() {
104: $parser = parent::getOptionParser();
105:
106: $parser->description(
107: __d('cake_console', 'Used by shells like bash to autocomplete command name, options and arguments')
108: )->addSubcommand('commands', array(
109: 'help' => __d('cake_console', 'Output a list of available commands'),
110: 'parser' => array(
111: 'description' => __d('cake_console', 'List all availables'),
112: 'arguments' => array(
113: )
114: )
115: ))->addSubcommand('subcommands', array(
116: 'help' => __d('cake_console', 'Output a list of available subcommands'),
117: 'parser' => array(
118: 'description' => __d('cake_console', 'List subcommands for a command'),
119: 'arguments' => array(
120: 'command' => array(
121: 'help' => __d('cake_console', 'The command name'),
122: 'required' => true,
123: )
124: )
125: )
126: ))->addSubcommand('options', array(
127: 'help' => __d('cake_console', 'Output a list of available options'),
128: 'parser' => array(
129: 'description' => __d('cake_console', 'List options'),
130: 'arguments' => array(
131: 'command' => array(
132: 'help' => __d('cake_console', 'The command name'),
133: 'required' => false,
134: )
135: )
136: )
137: ))->epilog(
138: __d('cake_console', 'This command is not intended to be called manually')
139: );
140:
141: return $parser;
142: }
143:
144: 145: 146: 147: 148: 149:
150: protected function _output($options = array()) {
151: if ($options) {
152: return $this->out(implode($options, ' '));
153: }
154: }
155: }
156: