Changing ShellDispatcher to use --help and -h like the option parser does.

This commit is contained in:
mark_story 2010-10-09 20:33:31 -04:00
parent 7f5b5c4fbd
commit 0d522f3bd4
3 changed files with 8 additions and 47 deletions

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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
*