#!/usr/local/bin/php runCommand(); } catch (DependencyException|NotFoundException $e) { echo $e->getMessage(); exit(1); } catch (Exception $e) { echo $e->getMessage(); } /** * @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; }