@vexify-org/yaggs 6.9.0 → 6.11.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 +61 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -165,6 +165,14 @@ class Yaggs {
|
|
|
165
165
|
return this.parser.spinner(message);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
async confirm(message, options = {}) {
|
|
169
|
+
return this.parser.confirm(message, options);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async select(options, question = 'Select an option') {
|
|
173
|
+
return this.parser.select(options, question);
|
|
174
|
+
}
|
|
175
|
+
|
|
168
176
|
check(fn) {
|
|
169
177
|
this.middleware(fn);
|
|
170
178
|
return this;
|
package/lib/parser.js
CHANGED
|
@@ -950,6 +950,67 @@ complete -c ${this.scriptName} `;
|
|
|
950
950
|
return { stop };
|
|
951
951
|
}
|
|
952
952
|
|
|
953
|
+
async confirm(message, options = {}) {
|
|
954
|
+
const readline = require('readline');
|
|
955
|
+
const rl = readline.createInterface({
|
|
956
|
+
input: process.stdin,
|
|
957
|
+
output: process.stdout
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
return new Promise((resolve) => {
|
|
961
|
+
const defaultValue = options.default !== undefined ? (options.default ? 'Y/n' : 'y/N') : 'y/N';
|
|
962
|
+
|
|
963
|
+
rl.question(`\u001b[33m${message} [${defaultValue}]:\u001b[0m `, (input) => {
|
|
964
|
+
const answer = input.trim().toLowerCase();
|
|
965
|
+
|
|
966
|
+
let result;
|
|
967
|
+
if (answer === '') {
|
|
968
|
+
result = options.default !== undefined ? options.default : false;
|
|
969
|
+
} else {
|
|
970
|
+
result = ['yes', 'y', 'true', '1'].includes(answer);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
rl.close();
|
|
974
|
+
resolve(result);
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
async select(options, question = 'Select an option') {
|
|
980
|
+
const readline = require('readline');
|
|
981
|
+
const rl = readline.createInterface({
|
|
982
|
+
input: process.stdin,
|
|
983
|
+
output: process.stdout
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
return new Promise((resolve) => {
|
|
987
|
+
console.log(`\u001b[34m${question}:\u001b[0m`);
|
|
988
|
+
|
|
989
|
+
options.forEach((opt, index) => {
|
|
990
|
+
const display = typeof opt === 'object' ? opt.value : opt;
|
|
991
|
+
const description = typeof opt === 'object' && opt.description ? ` - ${opt.description}` : '';
|
|
992
|
+
console.log(` ${index + 1}. ${display}${description}`);
|
|
993
|
+
});
|
|
994
|
+
|
|
995
|
+
rl.question('\u001b[34mEnter your choice:\u001b[0m ', (input) => {
|
|
996
|
+
const choice = parseInt(input.trim(), 10);
|
|
997
|
+
|
|
998
|
+
if (isNaN(choice) || choice < 1 || choice > options.length) {
|
|
999
|
+
console.log('\u001b[31mInvalid choice!\u001b[0m');
|
|
1000
|
+
rl.close();
|
|
1001
|
+
resolve(null);
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
const selected = options[choice - 1];
|
|
1006
|
+
const result = typeof selected === 'object' ? selected.value : selected;
|
|
1007
|
+
|
|
1008
|
+
rl.close();
|
|
1009
|
+
resolve(result);
|
|
1010
|
+
});
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
|
|
953
1014
|
getHelp() {
|
|
954
1015
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
955
1016
|
|