Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions cli/initSQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,33 @@
error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');

$options = getopt('', ['yes', 'help']) ?: [];
if (isset($options['help'])) {
echo <<<'TEXT'
Usage:
php cli/initSQLite.php [--yes] [--help]

Options:
--yes Run without the confirmation prompt.
--help Show this help.

TEXT;
return 0;
}

Initialize::init();

echo 'Welcome NeNe-PHP CLI!' . PHP_EOL . PHP_EOL;
echo 'This command initializes the SQLite database used by the fallback sample runtime.' . PHP_EOL;
echo 'Target file: ' . DB_DIR . DB_FILE . PHP_EOL . PHP_EOL;
echo 'Do you want to initialize SQLite? (Y/N)' . PHP_EOL;

$answer = trim((string)fgets(STDIN));
if (!in_array(strtolower($answer), ['y', 'yes'], true)) {
echo 'OK. Bye!' . PHP_EOL;
return 0;
if (!isset($options['yes'])) {
echo 'Do you want to initialize SQLite? (Y/N)' . PHP_EOL;
$answer = trim((string)fgets(STDIN));
if (!in_array(strtolower($answer), ['y', 'yes'], true)) {
echo 'OK. Bye!' . PHP_EOL;
return 0;
}
}

try {
Expand Down