File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,15 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email
22
22
process . exit ( 1 ) ;
23
23
}
24
24
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
+
25
34
// Using an async function to be able to use await inside
26
35
async function createUser ( argv ) {
27
36
const existing_user = await models . User . findOne ( { where : { email : argv [ "add" ] } } ) ;
@@ -31,14 +40,8 @@ async function createUser(argv) {
31
40
process . exit ( 1 ) ;
32
41
}
33
42
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
+
42
45
43
46
// Lets try to create, and check success
44
47
const ref = await models . User . create ( { email : argv [ "add" ] , password : pass } ) ;
You can’t perform that action at this time.
0 commit comments