Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Misc. cleanup and refactoring in `\console\Command`.

  • Loading branch information...
commit 1902698c24e46c655988c3dbc7af5ddd83727d29 1 parent 3b0c3ea
@nateabele nateabele authored
Showing with 8 additions and 15 deletions.
  1. +8 −15 libraries/lithium/console/Command.php
View
23 libraries/lithium/console/Command.php
@@ -184,17 +184,13 @@ public function error($error = null, $options = array('nl' => 1)) {
public function in($prompt = null, $options = array()) {
$defaults = array('choices' => null, 'default' => null, 'quit' => 'q');
$options += $defaults;
-
$choices = null;
+
if (is_array($options['choices'])) {
$choices = '(' . implode('/', $options['choices']) . ')';
}
-
- if ($options['default'] == null) {
- $this->out("{$prompt} {$choices} \n > ", false);
- } else {
- $this->out("{$prompt} {$choices} \n [{$options['default']}] > ", false);
- }
+ $default = $options['default'] ? "[{$options['default']}] " : '';
+ $this->out("{$prompt} {$choices} \n {$default}> ", false);
$result = null;
do {
@@ -204,8 +200,8 @@ public function in($prompt = null, $options = array()) {
&& !empty($options['choices']) && !in_array($result, $options['choices'], true)
);
- if ($options['default'] != null && empty($result)) {
- return $options['default'] ;
+ if ($options['default'] && !$result) {
+ return $options['default'];
}
return $result;
}
@@ -288,12 +284,8 @@ public function clear() {
* @return void
*/
public function stop($status = 0, $message = null) {
- if (!is_null($message)) {
- if ($status == 0) {
- $this->out($message);
- } else {
- $this->error($message);
- }
+ if ($message) {
+ ($status == 0) ? $this->out($message) : $this->error($message);
}
exit($status);
}
@@ -327,6 +319,7 @@ protected function _help() {
*/
protected function _response($type, $string, $options) {
$defaults = array('nl' => 1, 'style' => null);
+
if (!is_array($options)) {
if (!$options || is_int($options)) {
$options = array('nl' => $options);
Please sign in to comment.
Something went wrong with that request. Please try again.