File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
2635async 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 } ) ;
You can’t perform that action at this time.
0 commit comments