* php tools/make-user.php --list */ require __DIR__ . '/../api/lib/UserStore.php'; $file = dirname(__DIR__) . '/data/users.json'; $store = new UserStore($file); $args = array_slice($argv, 1); if (($args[0] ?? '') === '--list') { foreach ($store->names() as $name) { echo $name, "\n"; } exit(0); } if (count($args) !== 2 || $args[0] === '' || $args[1] === '') { fwrite(STDERR, "Usage: php tools/make-user.php \n"); exit(2); } [$username, $password] = $args; if (!UserStore::isValidName($username)) { fwrite(STDERR, "Invalid user name: {$username}\n"); exit(2); } $existed = $store->exists($username); $store->put($username, $password); echo ($existed ? 'password set for ' : 'created '), $username, "\n";