@vexify-org/yaggs 6.11.0 → 6.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -0
- package/lib/parser.js +86 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -173,6 +173,14 @@ class Yaggs {
|
|
|
173
173
|
return this.parser.select(options, question);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
async password(message = 'Enter password') {
|
|
177
|
+
return this.parser.password(message);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async http(url, options = {}) {
|
|
181
|
+
return this.parser.http(url, options);
|
|
182
|
+
}
|
|
183
|
+
|
|
176
184
|
check(fn) {
|
|
177
185
|
this.middleware(fn);
|
|
178
186
|
return this;
|
package/lib/parser.js
CHANGED
|
@@ -1011,6 +1011,92 @@ complete -c ${this.scriptName} `;
|
|
|
1011
1011
|
});
|
|
1012
1012
|
}
|
|
1013
1013
|
|
|
1014
|
+
async password(message = 'Enter password') {
|
|
1015
|
+
const readline = require('readline');
|
|
1016
|
+
const rl = readline.createInterface({
|
|
1017
|
+
input: process.stdin,
|
|
1018
|
+
output: process.stdout,
|
|
1019
|
+
terminal: true
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
return new Promise((resolve) => {
|
|
1023
|
+
const stdin = process.stdin;
|
|
1024
|
+
const stdout = process.stdout;
|
|
1025
|
+
|
|
1026
|
+
stdin.setRawMode(true);
|
|
1027
|
+
|
|
1028
|
+
let password = '';
|
|
1029
|
+
|
|
1030
|
+
stdout.write(`\u001b[34m${message}:\u001b[0m `);
|
|
1031
|
+
|
|
1032
|
+
const onData = (data) => {
|
|
1033
|
+
const char = data.toString('utf8');
|
|
1034
|
+
|
|
1035
|
+
if (char === '\n' || char === '\r') {
|
|
1036
|
+
stdin.setRawMode(false);
|
|
1037
|
+
stdout.write('\n');
|
|
1038
|
+
stdin.removeListener('data', onData);
|
|
1039
|
+
rl.close();
|
|
1040
|
+
resolve(password);
|
|
1041
|
+
} else if (char === '\u0008' || char === '\u007f') {
|
|
1042
|
+
if (password.length > 0) {
|
|
1043
|
+
password = password.slice(0, -1);
|
|
1044
|
+
stdout.write('\u0008 \u0008');
|
|
1045
|
+
}
|
|
1046
|
+
} else if (char.charCodeAt(0) === 3) {
|
|
1047
|
+
process.exit(1);
|
|
1048
|
+
} else {
|
|
1049
|
+
password += char;
|
|
1050
|
+
stdout.write('*');
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
stdin.on('data', onData);
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
async http(url, options = {}) {
|
|
1059
|
+
const https = require('https');
|
|
1060
|
+
const http = require('http');
|
|
1061
|
+
|
|
1062
|
+
const protocol = url.startsWith('https') ? https : http;
|
|
1063
|
+
const method = options.method || 'GET';
|
|
1064
|
+
const headers = options.headers || {};
|
|
1065
|
+
const body = options.body ? JSON.stringify(options.body) : null;
|
|
1066
|
+
|
|
1067
|
+
if (body && !headers['Content-Type']) {
|
|
1068
|
+
headers['Content-Type'] = 'application/json';
|
|
1069
|
+
}
|
|
1070
|
+
if (body && !headers['Content-Length']) {
|
|
1071
|
+
headers['Content-Length'] = Buffer.byteLength(body);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
return new Promise((resolve, reject) => {
|
|
1075
|
+
const req = protocol.request(url, { method, headers }, (res) => {
|
|
1076
|
+
let data = '';
|
|
1077
|
+
|
|
1078
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
1079
|
+
|
|
1080
|
+
res.on('end', () => {
|
|
1081
|
+
try {
|
|
1082
|
+
const parsed = JSON.parse(data);
|
|
1083
|
+
resolve({ status: res.statusCode, headers: res.headers, body: parsed });
|
|
1084
|
+
} catch {
|
|
1085
|
+
resolve({ status: res.statusCode, headers: res.headers, body: data });
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
req.on('error', reject);
|
|
1091
|
+
|
|
1092
|
+
if (body) {
|
|
1093
|
+
req.write(body);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
req.end();
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1014
1100
|
getHelp() {
|
|
1015
1101
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
1016
1102
|
|