File tree Expand file tree Collapse file tree 1 file changed +19
-26
lines changed
Expand file tree Collapse file tree 1 file changed +19
-26
lines changed Original file line number Diff line number Diff line change @@ -17,37 +17,30 @@ class Cli {
1717 public function input (string $ prompt , $ validInputs , string $ default = '' ): string
1818 {
1919 echo $ prompt ;
20-
2120 $ input = trim (fgets (fopen ('php://stdin ' , 'rb ' )));
22-
23- while (true ) {
24- if ($ input === '' && $ default !== '' ) {
25- return $ default ;
26- }
27-
28- if ($ validInputs === 'is_file ' && !is_file ($ input )) {
29- echo $ prompt ;
30- $ input = trim (fgets (STDIN ));
31- continue ;
32- }
33-
34- if (is_array ($ validInputs ) && !in_array ($ input , $ validInputs , true )) {
35- echo $ prompt ;
36- $ input = trim (fgets (STDIN ));
37- continue ;
38- }
39-
40- if (is_string ($ validInputs ) && !empty ($ validInputs ) && ($ input !== $ validInputs )) {
41- echo $ prompt ;
42- $ input = trim (fgets (STDIN ));
43- continue ;
21+ while (
22+ !isset ($ input ) ||
23+ (
24+ is_array ($ validInputs ) &&
25+ !in_array ($ input , $ validInputs , true )
26+ ) ||
27+ (
28+ $ validInputs === 'is_file ' &&
29+ !is_file ($ input )
30+ ) ||
31+ (
32+ !empty ($ validInputs ) && $ input !== $ validInputs
33+ )
34+ ){
35+ echo $ prompt ;
36+ $ input = trim (fgets (fopen ('php://stdin ' , 'rb ' )));
37+ if (empty ($ input ) && !empty ($ default )) {
38+ $ input = $ default ;
4439 }
45-
46- return $ input ;
4740 }
41+ return $ input ;
4842 }
4943
50-
5144 /**
5245 * @param string $output
5346 */
You can’t perform that action at this time.
0 commit comments