Skip to content

Commit

Permalink
Changing ShellDispatcher to use --help and -h like the option parser …
Browse files Browse the repository at this point in the history
…does.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 7f5b5c4 commit 0d522f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 47 deletions.
1 change: 1 addition & 0 deletions cake/console/console_option_parser.php
Expand Up @@ -238,6 +238,7 @@ public function options() {
* @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();
Expand Down
2 changes: 1 addition & 1 deletion cake/console/libs/command_list.php
Expand Up @@ -96,6 +96,6 @@ public function main() {
}
$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);
}
}
52 changes: 6 additions & 46 deletions cake/console/shell_dispatcher.php
Expand Up @@ -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.
Expand All @@ -26,14 +27,6 @@
*/
class ShellDispatcher {

/**
* Standard input stream.
*
* @var filehandle
* @access public
*/
public $stdin;

/**
* Contains command switches parsed from the command line.
*
Expand Down Expand Up @@ -252,18 +245,18 @@ function __bootstrap() {
* @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';
Expand Down Expand Up @@ -363,39 +356,6 @@ protected function _getShell($plugin = null) {
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
*
Expand Down

0 comments on commit 0d522f3

Please sign in to comment.