Skip to content

Commit 79842b8

Browse files
committed
refactor(bin): add function getPass in bin/manage_users
Signed-off-by: Erona <[email protected]>
1 parent 63626b1 commit 79842b8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

bin/manage_users

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email
2222
process.exit(1);
2323
}
2424

25+
function getPass(argv, action) {
26+
// Find whether we use cmdline or prompt password
27+
if(typeof argv["pass"] !== 'string') {
28+
return readline.question(`Password for ${argv[action]}:`, {hideEchoBack: true});
29+
}
30+
console.log("Using password from commandline...");
31+
return argv["pass"];
32+
}
33+
2534
// Using an async function to be able to use await inside
2635
async function createUser(argv) {
2736
const existing_user = await models.User.findOne({where: {email: argv["add"]}});
@@ -31,14 +40,8 @@ async function createUser(argv) {
3140
process.exit(1);
3241
}
3342

34-
// Find whether we use cmdline or prompt password
35-
let pass;
36-
if(argv["pass"] == undefined) {
37-
pass = readline.question(`Password for ${argv["add"]}:`, {hideEchoBack: true});
38-
} else {
39-
console.log("Using password from commandline...");
40-
pass = "" + argv["pass"];
41-
}
43+
const pass = getPass(argv, "add");
44+
4245

4346
// Lets try to create, and check success
4447
const ref = await models.User.create({email: argv["add"], password: pass});

0 commit comments

Comments
 (0)