@launchql/cli
Version:
LaunchQL CLI
90 lines (85 loc) • 3.26 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@launchql/core");
const logger_1 = require("@launchql/logger");
const pg_env_1 = require("pg-env");
const log = new logger_1.Logger('admin-users-add');
const addUsageText = `
LaunchQL Admin Users Add Command:
lql admin-users add [OPTIONS]
Add database users with LaunchQL roles.
Note: You must run 'lql admin-users bootstrap' first to initialize roles.
Options:
--help, -h Show this help message
--username <username> Username for the database user
--password <password> Password for the database user
--test Add test users (app_user, app_admin) with default passwords
--cwd <directory> Working directory (default: current directory)
Examples:
lql admin-users add --username myuser --password mypass
lql admin-users add --test # Add test users (requires bootstrap first)
lql admin-users add # Will prompt for username and password
`;
exports.default = async (argv, prompter, _options) => {
// Show usage if explicitly requested
if (argv.help || argv.h) {
console.log(addUsageText);
process.exit(0);
}
const pgEnv = (0, pg_env_1.getPgEnvOptions)();
const isTest = argv.test;
const init = new core_1.LaunchQLInit(pgEnv);
try {
if (isTest) {
const { yes: confirmTest } = await prompter.prompt(argv, [
{
type: 'confirm',
name: 'yes',
message: 'Are you sure you want to add LaunchQL test users? (WARNING: Should NEVER be run on production!)',
default: false
}
]);
if (!confirmTest) {
log.info('Operation cancelled.');
return;
}
await init.bootstrapTestRoles();
log.success('Test users added successfully.');
}
else {
const prompts = [
{
type: 'text',
name: 'username',
message: 'Enter username for database user:',
validate: (input) => input && input.trim().length > 0
},
{
type: 'text',
name: 'password',
message: 'Enter password for database user:',
validate: (input) => input && input.trim().length > 0
}
];
const { username, password } = await prompter.prompt(argv, prompts);
const { yes } = await prompter.prompt(argv, [
{
type: 'confirm',
name: 'yes',
message: `Are you sure you want to add database user "${username}"?`,
default: false
}
]);
if (!yes) {
log.info('Operation cancelled.');
return;
}
await init.bootstrapDbRoles(username, password);
log.success(`Database user "${username}" added successfully.`);
}
}
finally {
await init.close();
}
return argv;
};
;