From 0d522f3bd4a4b9c6fcd67f80017d108db2486135 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 9 Oct 2010 20:33:31 -0400 Subject: [PATCH] Changing ShellDispatcher to use --help and -h like the option parser does. --- cake/console/console_option_parser.php | 1 + cake/console/libs/command_list.php | 2 +- cake/console/shell_dispatcher.php | 52 +++----------------------- 3 files changed, 8 insertions(+), 47 deletions(-) diff --git a/cake/console/console_option_parser.php b/cake/console/console_option_parser.php index ef8cafdfa..95fa79409 100644 --- a/cake/console/console_option_parser.php +++ b/cake/console/console_option_parser.php @@ -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(); diff --git a/cake/console/libs/command_list.php b/cake/console/libs/command_list.php index d48a9ae4f..79faceb5b 100644 --- a/cake/console/libs/command_list.php +++ b/cake/console/libs/command_list.php @@ -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); } } diff --git a/cake/console/shell_dispatcher.php b/cake/console/shell_dispatcher.php index d01a72acf..04e9904a3 100644 --- a/cake/console/shell_dispatcher.php +++ b/cake/console/shell_dispatcher.php @@ -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 *