-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathtest-setup-prompt.js
More file actions
108 lines (102 loc) · 2.78 KB
/
Copy pathtest-setup-prompt.js
File metadata and controls
108 lines (102 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var read = require("read");
var mlutil = require('../lib/mlutil.js');
function adminUserPrompt() {
var self = this;
if (self.user === null) {
read({
prompt: 'admin user (default=admin): '
},
mlutil.callbackOn(self, adminUserCallback)
);
} else {
self.passwordPrompt();
}
}
function adminUserCallback(error, result) {
if (error) {
console.log(error);
process.exit(1);
}
this.user = (result === '') ? 'admin' : result;
this.passwordPrompt();
}
function adminPasswordPrompt() {
var self = this;
if (self.password === null) {
read({
prompt: (self.user === 'admin') ?
'admin password (default=admin): ' : 'admin password: ',
silent: true,
replace: '*',
edit: false
},
mlutil.callbackOn(self, adminPasswordCallback)
);
} else {
self.finish();
}
}
function adminPasswordCallback(error, result) {
if (error) {
console.log(error);
process.exit(1);
}
if (result === '') {
if (this.user === 'admin') {
this.password = 'admin';
} else {
console.log('no admin password specified, so cannot setup');
process.exit(1);
}
} else {
this.password = result;
}
this.finish();
}
function adminFinish() {
this.done(this.user, this.password);
}
function AdminPrompter(done) {
this.done = done;
this.user = null;
this.password = null;
}
AdminPrompter.prototype.userPrompt = adminUserPrompt;
AdminPrompter.prototype.userCallback = adminUserCallback;
AdminPrompter.prototype.passwordPrompt = adminPasswordPrompt;
AdminPrompter.prototype.passwordCallback = adminPasswordCallback;
AdminPrompter.prototype.finish = adminFinish;
function promptForAdmin(done) {
var prompter = new AdminPrompter(done);
var argvLen = process.argv.length;
if (argvLen >= 4) {
var argvMax = argvLen - 1;
for (var argvI=2; argvI < argvMax; argvI++) {
var argvVal = process.argv[argvI];
if (argvVal === '-u') {
argvVal = process.argv[argvI + 1];
var argvSep = argvVal.indexOf(':');
if (argvSep < 0) {
prompter.user = argvVal;
break;
}
if (argvSep > 0) {
prompter.user = argvVal.substring(0, argvSep);
}
if (argvSep < (argvVal.length - 1)) {
prompter.password = argvVal.substring(argvSep + 1);
}
break;
} else if (argvVal === '-h') {
console.log('usage: '+process.argv[1]+' [-u adminUser:adminPassword]');
console.log('without -u, prompts for admin user and/or admin password');
process.exit();
}
};
}
prompter.userPrompt();
}
module.exports = promptForAdmin;