#!/usr/bin/keyhelp-php81 getMessage() . PHP_EOL; exit(1); } $app->runCommand(); /** * @param String $message * @param array $options * @param string $default * * @return bool */ function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'], string $default = 'n'): bool { // first $options means true, any other false echo $message, ' ('; $first = true; foreach ($options as $option) { // mark default if ($option == $default) { $option = strtoupper(string: $option); } if ($first) { echo $option; $first = false; } else { echo '/', $option; } } echo '): '; $handle = fopen(filename: "php://stdin", mode: 'r'); $line = trim(string: fgetc(stream: $handle)); fclose(stream: $handle); if ($line == '') { // enter $line = $default; } if ($line == $options[0]) { $result = true; } else { $result = false; } return $result; }