20 return \rtrim(\fgets(STDIN));
30 public static function question($prompt, array $propositions =
null, array $options = []) {
32 $hiddenProposals = $options[
'hiddenProposals'] ?? [];
33 $continue =
function ($rep, $array) {
34 return \array_search($rep, $array) ===
false;
36 if (isset($options[
'default'])) {
39 if (isset($options[
'ignoreCase'])) {
40 $continue =
function ($rep, $array) {
41 return \array_search(\strtolower($rep), \array_map(
'strtolower', $array)) ===
false;
45 if (\is_array($propositions)) {
46 if (\count($propositions) > 2) {
48 foreach ($propositions as $index => $prop) {
49 $dec = 2 - \strlen(($index + 1) .
'');
50 $props .=
"[" . ($index + 1) .
"] " . str_repeat(
' ', $dec) . $prop .
"\n";
55 }
while ((
int) $answer != $answer || ! isset($propositions[(
int) $answer - 1]));
56 $answer = $propositions[(int) $answer - 1];
58 echo
" (" . implode(
"/", $propositions) .
")\n";
59 $propositions = \array_merge($propositions, $hiddenProposals);
62 }
while ($continue($answer, $propositions));
67 if (isset($options[
'default']) && $answer ==
'') {
68 $answer = $options[
'default'];
76 ], array $options = []) {
79 'hiddenProposals' => [
86 public static function explodeResponse(
string $response, $callback =
'trim',
string $separator =
',') {
87 return \array_map($callback, \array_filter(\explode($separator, \trim($response)),
'strlen'));
96 public static function isYes($answer) {
97 return \array_search(\trim($answer), [
109 public static function isNo($answer) {
110 return \array_search(\trim($answer), [
123 return \array_search(\trim($answer), [
135 $argv[0]=\realpath($argv[0]);
136 \system(PHP_BINARY.
' '.\implode(
' ',$argv));