diff --git "a/include/class-cli\\Input.php" "b/include/class-cli\\Input.php" index 2d8acb0..c788687 100644 --- "a/include/class-cli\\Input.php" +++ "b/include/class-cli\\Input.php" @@ -1,75 +1,80 @@ . # Command line interface namespace cli; class Input { /** * Do a yes/no question * * @param $question string e.g. 'Do you want to continue?' * @param $default string e.g. 'y' * @return string e.g. 'y' */ public static function yesNoQuestion( $question, $default = 'y' ) { return self::askSingleChar( $question, 'yn', $default ); } /** * Do a single character question * * @param $question string e.g. 'Do you want to continue?' * @param $choices string e.g. 'yn' * @param $default string e.g. 'y' */ public static function askSingleChar( $question, $choices, $default ) { $choices = str_split( $choices ); foreach( $choices as &$choice ) { if( $choice === $default ) { $choice = strtoupper( $choice ); } } - return self::askInput( "$question [" . implode( '/', $choices ) . "]", $default ); + + // ask the user input + $result = self::askInput( "$question [" . implode( '/', $choices ) . "]", $default ); + + // eventually convert the default Y to y again + return strtolower( $result ); } /** * Ask for user input * * @param $question string e.g. 'Please insert something' * @param $default string e.g. 'something' * @return string e.g. 'something' */ public static function askInput( $question, $default = '' ) { echo "$question\n"; return self::read( $default ); } /** * Ask for user standard input * * @param $default string Default string when empty input * @return string */ public static function read( $default = '' ) { $handle = fopen( 'php://stdin', 'r' ); $line = rtrim( fgets( $handle ) ); fclose( $handle ); return '' === $line ? $default : $line; } }