Skip to content

Commit dd61a04

Browse files
committed
docs: Removed Examples
1 parent 6b3aad9 commit dd61a04

File tree

14 files changed

+13
-2410
lines changed

14 files changed

+13
-2410
lines changed

WebFiori/Cli/Command.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,18 @@ public function removeArgument(string $name) : bool {
10351035
* @param int $defaultIndex The index of the default value in case no value
10361036
* is selected and the user hit enter.
10371037
*
1038+
* * @param int $maxTrials The maximum number of trials the user can do to select
1039+
* a value. If -1 is passed, the user can select a value forever.
1040+
*
10381041
* @return string|null The method will return the value which is selected by
1039-
* the user. If choices array is empty, null is returned.
1042+
* the user. If choices array is empty, null is returned. Also, null is returned
1043+
* if max trials is reached and it is not -1.
1044+
*
10401045
*
10411046
*/
1042-
public function select(string $prompt, array $choices, int $defaultIndex = -1): ?string {
1047+
public function select(string $prompt, array $choices, int $defaultIndex = -1, int $maxTrials = -1): ?string {
10431048
if (count($choices) != 0) {
1049+
$currentTry = 0;
10441050
do {
10451051
$this->println($prompt, [
10461052
'color' => 'gray',
@@ -1055,6 +1061,11 @@ public function select(string $prompt, array $choices, int $defaultIndex = -1):
10551061
if ($check !== null) {
10561062
return $check;
10571063
}
1064+
$currentTry++;
1065+
1066+
if ($currentTry == $maxTrials && $maxTrials > 0) {
1067+
return null;
1068+
}
10581069
} while (true);
10591070
}
10601071

0 commit comments

Comments
 (0)