mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Changing ShellDispatcher to use --help and -h like the option parser does.
This commit is contained in:
parent
7f5b5c4fbd
commit
0d522f3bd4
3 changed files with 8 additions and 47 deletions
|
@ -238,6 +238,7 @@ class ConsoleOptionParser {
|
|||
* @param array $argv Array of args (argv) to parse
|
||||
* @return Array array($params, $args)
|
||||
* @throws InvalidArgumentException When an invalid parameter is encountered.
|
||||
* RuntimeException when required arguments are not supplied.
|
||||
*/
|
||||
public function parse($argv) {
|
||||
$params = $args = array();
|
||||
|
|
|
@ -96,6 +96,6 @@ class CommandListShell extends Shell {
|
|||
}
|
||||
$this->out();
|
||||
$this->out("To run a command, type 'cake shell_name [args]'");
|
||||
$this->out("To get help on a specific command, type 'cake shell_name help'", 2);
|
||||
$this->out("To get help on a specific command, type 'cake shell_name --help'", 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
require_once 'console_option_parser.php';
|
||||
|
||||
/**
|
||||
* Shell dispatcher handles dispatching cli commands.
|
||||
|
@ -26,14 +27,6 @@
|
|||
*/
|
||||
class ShellDispatcher {
|
||||
|
||||
/**
|
||||
* Standard input stream.
|
||||
*
|
||||
* @var filehandle
|
||||
* @access public
|
||||
*/
|
||||
public $stdin;
|
||||
|
||||
/**
|
||||
* Contains command switches parsed from the command line.
|
||||
*
|
||||
|
@ -252,18 +245,18 @@ class ShellDispatcher {
|
|||
* @return boolean
|
||||
*/
|
||||
public function dispatch() {
|
||||
$arg = $this->shiftArgs();
|
||||
$command = $this->shiftArgs();
|
||||
|
||||
if (!$arg) {
|
||||
if (!$command) {
|
||||
$this->help();
|
||||
return false;
|
||||
}
|
||||
if ($arg == 'help') {
|
||||
if (in_array($command, array('help', '--help', '-h'))) {
|
||||
$this->help();
|
||||
return true;
|
||||
}
|
||||
|
||||
list($plugin, $shell) = pluginSplit($arg);
|
||||
|
||||
list($plugin, $shell) = pluginSplit($command);
|
||||
$this->shell = $shell;
|
||||
$this->shellName = Inflector::camelize($shell);
|
||||
$this->shellClass = $this->shellName . 'Shell';
|
||||
|
@ -363,39 +356,6 @@ class ShellDispatcher {
|
|||
return $Shell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts the user for input, and returns it.
|
||||
*
|
||||
* @param string $prompt Prompt text.
|
||||
* @param mixed $options Array or string of options.
|
||||
* @param string $default Default input value.
|
||||
* @return Either the default value, or the user-provided input.
|
||||
*/
|
||||
public function getInput($prompt, $options = null, $default = null) {
|
||||
if (!is_array($options)) {
|
||||
$printOptions = '';
|
||||
} else {
|
||||
$printOptions = '(' . implode('/', $options) . ')';
|
||||
}
|
||||
|
||||
if ($default === null) {
|
||||
$this->stdout($prompt . " $printOptions \n" . '> ', false);
|
||||
} else {
|
||||
$this->stdout($prompt . " $printOptions \n" . "[$default] > ", false);
|
||||
}
|
||||
$result = fgets($this->stdin);
|
||||
|
||||
if ($result === false) {
|
||||
exit;
|
||||
}
|
||||
$result = trim($result);
|
||||
|
||||
if ($default != null && empty($result)) {
|
||||
return $default;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses command line options
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue