2013-09-13 22:36:57 +00:00
|
|
|
<?php
|
2013-09-16 12:11:27 +00:00
|
|
|
/**
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2013-09-16 12:11:27 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP Project
|
2013-09-16 12:11:27 +00:00
|
|
|
* @package Cake.Console.Command
|
|
|
|
* @since CakePHP v 2.5
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2013-09-16 12:11:27 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-28 15:42:28 +00:00
|
|
|
App::uses('AppShell', 'Console/Command');
|
2013-09-13 22:36:57 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-16 12:11:27 +00:00
|
|
|
* Provide command completion shells such as bash.
|
|
|
|
*
|
|
|
|
* @package Cake.Console.Command
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
2013-09-28 15:42:28 +00:00
|
|
|
class CompletionShell extends AppShell {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains tasks to load and instantiate
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $tasks = array('Command');
|
2013-09-13 22:36:57 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-16 12:11:27 +00:00
|
|
|
* Echo no header by overriding the startup method
|
2013-09-13 22:36:57 +00:00
|
|
|
*
|
2013-09-16 12:11:27 +00:00
|
|
|
* @return void
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
public function startup() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-16 12:11:27 +00:00
|
|
|
* Not called by the autocomplete shell - this is for curious users
|
|
|
|
*
|
|
|
|
* @return void
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
public function main() {
|
2013-09-28 15:42:28 +00:00
|
|
|
return $this->out($this->getOptionParser()->help());
|
2013-09-13 22:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* list commands
|
2013-09-16 12:11:27 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
public function commands() {
|
2013-09-28 15:42:28 +00:00
|
|
|
$options = $this->Command->commands();
|
2013-09-13 22:36:57 +00:00
|
|
|
return $this->_output($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* list options for the named command
|
2013-09-16 12:11:27 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
public function options() {
|
2013-09-28 15:42:28 +00:00
|
|
|
$commandName = '';
|
|
|
|
if (!empty($this->args[0])) {
|
|
|
|
$commandName = $this->args[0];
|
2013-09-13 22:36:57 +00:00
|
|
|
}
|
2013-09-28 15:42:28 +00:00
|
|
|
$options = $this->Command->options($commandName);
|
2013-09-13 22:36:57 +00:00
|
|
|
|
|
|
|
return $this->_output($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* list subcommands for the named command
|
2013-09-16 12:11:27 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
public function subCommands() {
|
|
|
|
if (!$this->args) {
|
|
|
|
return $this->_output();
|
|
|
|
}
|
|
|
|
|
2013-09-28 15:42:28 +00:00
|
|
|
$options = $this->Command->subCommands($this->args[0]);
|
2013-09-13 22:36:57 +00:00
|
|
|
return $this->_output($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Guess autocomplete from the whole argument string
|
2013-09-16 12:11:27 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
public function fuzzy() {
|
|
|
|
return $this->_output();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-05 23:38:32 +00:00
|
|
|
* Gets the option parser instance and configures it.
|
2013-09-16 12:11:27 +00:00
|
|
|
*
|
|
|
|
* @return ConsoleOptionParser
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
public function getOptionParser() {
|
2013-09-23 12:44:21 +00:00
|
|
|
$parser = parent::getOptionParser();
|
2013-09-13 22:36:57 +00:00
|
|
|
|
2013-12-05 23:38:32 +00:00
|
|
|
$parser->description(
|
|
|
|
__d('cake_console', 'Used by shells like bash to autocomplete command name, options and arguments')
|
|
|
|
)->addSubcommand('commands', array(
|
|
|
|
'help' => __d('cake_console', 'Output a list of available commands'),
|
|
|
|
'parser' => array(
|
|
|
|
'description' => __d('cake_console', 'List all availables'),
|
|
|
|
'arguments' => array(
|
2013-09-13 22:36:57 +00:00
|
|
|
)
|
2013-12-05 23:38:32 +00:00
|
|
|
)
|
|
|
|
))->addSubcommand('subcommands', array(
|
|
|
|
'help' => __d('cake_console', 'Output a list of available subcommands'),
|
|
|
|
'parser' => array(
|
|
|
|
'description' => __d('cake_console', 'List subcommands for a command'),
|
|
|
|
'arguments' => array(
|
|
|
|
'command' => array(
|
|
|
|
'help' => __d('cake_console', 'The command name'),
|
|
|
|
'required' => true,
|
2013-09-13 22:36:57 +00:00
|
|
|
)
|
|
|
|
)
|
2013-12-05 23:38:32 +00:00
|
|
|
)
|
|
|
|
))->addSubcommand('options', array(
|
|
|
|
'help' => __d('cake_console', 'Output a list of available options'),
|
|
|
|
'parser' => array(
|
|
|
|
'description' => __d('cake_console', 'List options'),
|
|
|
|
'arguments' => array(
|
|
|
|
'command' => array(
|
|
|
|
'help' => __d('cake_console', 'The command name'),
|
|
|
|
'required' => false,
|
2013-09-13 22:36:57 +00:00
|
|
|
)
|
|
|
|
)
|
2013-12-05 23:38:32 +00:00
|
|
|
)
|
|
|
|
))->epilog(
|
|
|
|
__d('cake_console', 'This command is not intended to be called manually')
|
|
|
|
);
|
|
|
|
|
2013-09-13 22:36:57 +00:00
|
|
|
return $parser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emit results as a string, space delimited
|
|
|
|
*
|
2014-05-28 03:34:53 +00:00
|
|
|
* @param array $options The options to output
|
2013-09-16 12:11:27 +00:00
|
|
|
* @return void
|
2013-09-13 22:36:57 +00:00
|
|
|
*/
|
|
|
|
protected function _output($options = array()) {
|
|
|
|
if ($options) {
|
2020-06-17 17:44:23 +00:00
|
|
|
return $this->out(implode(' ', $options));
|
2013-09-13 22:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|