@@ -111,10 +111,11 @@ function input( $format = null ) {
111
111
* Displays an input prompt. If no default value is provided the prompt will
112
112
* continue displaying until input is received.
113
113
*
114
- * @param string $question The question to ask the user.
115
- * @param string $default A default value if the user provides no input.
116
- * @param string $marker A string to append to the question and default value
117
- * on display.
114
+ * @param string $question The question to ask the user.
115
+ * @param bool|string $default A default value if the user provides no input.
116
+ * @param string $marker A string to append to the question and default value
117
+ * on display.
118
+ * @param boolean $hide Optionally hides what the user types in.
118
119
* @return string The users input.
119
120
* @see cli\input()
120
121
*/
@@ -126,25 +127,41 @@ function prompt( $question, $default = false, $marker = ': ' ) {
126
127
* Presents a user with a multiple choice question, useful for 'yes/no' type
127
128
* questions (which this function defaults too).
128
129
*
129
- * @param string $question The question to ask the user.
130
- * @param string $valid A string of characters allowed as a response. Case
131
- * is ignored.
132
- * @param string $default The default choice. NULL if a default is not allowed.
130
+ * @param string $question The question to ask the user.
131
+ * @param string $choice
132
+ * @param string|null $default The default choice. NULL if a default is not allowed.
133
+ * @internal param string $valid A string of characters allowed as a response. Case
134
+ * is ignored.
133
135
* @return string The users choice.
134
- * @see cli\prompt()
136
+ * @see cli\prompt()
135
137
*/
136
138
function choose ( $ question , $ choice = 'yn ' , $ default = 'n ' ) {
137
139
return \cli \Streams::choose ( $ question , $ choice , $ default );
138
140
}
139
141
142
+ /**
143
+ * Does the same as {@see choose()}, but always asks yes/no and returns a boolean
144
+ *
145
+ * @param string $question The question to ask the user.
146
+ * @param bool|null $default The default choice, in a boolean format.
147
+ * @return bool
148
+ */
149
+ function confirm ( $ question , $ default = false ) {
150
+ if ( is_bool ( $ default ) ) {
151
+ $ default = $ default ? 'y ' : 'n ' ;
152
+ }
153
+ $ result = choose ( $ question , 'yn ' , $ default );
154
+ return $ result == 'y ' ;
155
+ }
156
+
140
157
/**
141
158
* Displays an array of strings as a menu where a user can enter a number to
142
159
* choose an option. The array must be a single dimension with either strings
143
160
* or objects with a `__toString()` method.
144
161
*
145
- * @param array $items The list of items the user can choose from.
146
- * @param string $default The index of the default item.
147
- * @param string $title The message displayed to the user when prompted.
162
+ * @param array $items The list of items the user can choose from.
163
+ * @param bool| string $default The index of the default item.
164
+ * @param string $title The message displayed to the user when prompted.
148
165
* @return string The index of the chosen item.
149
166
* @see cli\line()
150
167
* @see cli\input()
0 commit comments