From 6d750fe78e104dff458070c92f1b79ddc7eff03d Mon Sep 17 00:00:00 2001 From: lesion Date: Tue, 24 Oct 2023 17:34:39 +0200 Subject: [PATCH] allow to specify password while create new user via CLI --- server/cli/users.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/server/cli/users.js b/server/cli/users.js index f060f494..5439abaa 100644 --- a/server/cli/users.js +++ b/server/cli/users.js @@ -65,12 +65,17 @@ async function resetPassword (args) { async function create (args) { await _initializeDB() const { User } = require('../api/models/models') - const user = await User.create({ - email: args.email, - is_active: true, - is_admin: args.admin || false - }).catch(e => console.error(String(e))) - console.error(JSON.stringify(user, null, 2)) + try { + const user = await User.create({ + email: args.email, + password: args.password, + is_active: true, + is_admin: args.admin || false + }) + console.error(`User ${args.email} created`) + } catch(e) { + console.error(String(e)) + } await db.close() } @@ -106,11 +111,12 @@ const usersCLI = yargs => yargs }, resetPassword) .command('set-admin ', 'Set administrator privileges to the given user', {}, setAdmin) .command('unset-admin ', 'Remove administrator privileges to the given user', {}, unsetAdmin) - .command('create [admin]', 'Create an user', { - admin: { describe: 'Define this user as administrator', type: 'boolean' } + .command('create [password] [admin]', 'Create an user', { + admin: { describe: 'Define this user as administrator', type: 'boolean' }, }, create) .command('remove ', 'Remove an user', {}, remove) .positional('email', { describe: 'user email or username', type: 'string', demandOption: true }) + .positional('password', { describe: 'Password', type: 'string', demandOption: false }) .recommendCommands() .demandCommand(1, '') .argv