diff --git a/console.php b/console.php index 257b1bb..b0296f1 100644 --- a/console.php +++ b/console.php @@ -323,6 +323,8 @@ class console $this->debug ("Autocompletion : start='$start', end='$end'"); $completeArr = call_user_func ($this->completionFunction, self::tokenize ($start)); + if (! is_array ($completeArr)) + throw new \Exception ("Autocompletion : return is not an array"); $isAssoc = is_array ($completeArr) && array_diff_key ($completeArr, array_keys (array_keys ($completeArr))); // Remove from completeArr the proposed values which doesn't match with @@ -334,10 +336,13 @@ class console if (mb_substr ($val, 0, mb_strlen ($end)) !== $end) unset ($completeArr[$key]); } - if (count ($completeArr) === 1) + if (count ($completeArr) === 1 && + ($isAssoc && key ($completeArr) !== "" || + ! $isAssoc && reset ($completeArr) !== "")) { // One entry : add a space to put on the next - $this->debug ("Autocompletion : One entry : add it + ending space"); + $this->debug ("Autocompletion : One entry not empty : ". + "add it + ending space"); if ($isAssoc) $string = $start.key ($completeArr)." "; else