Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F15176557
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
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 @@
<?php
# Boz-MW - Another MediaWiki API handler in PHP
# Copyright (C) 2018 Valerio Bozzolan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 03:27 (22 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264433
Default Alt Text
(2 KB)
Attached To
Mode
R21 boz-mw: MediaWiki API client
Attached
Detach File
Event Timeline