@vexify-org/yaggs 6.7.0 → 6.8.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 +4 -0
- package/lib/parser.js +43 -0
- package/package.json +1 -1
package/index.js
CHANGED
package/lib/parser.js
CHANGED
|
@@ -881,6 +881,49 @@ complete -c ${this.scriptName} `;
|
|
|
881
881
|
});
|
|
882
882
|
}
|
|
883
883
|
|
|
884
|
+
async ask(question, options = {}) {
|
|
885
|
+
const readline = require('readline');
|
|
886
|
+
const rl = readline.createInterface({
|
|
887
|
+
input: process.stdin,
|
|
888
|
+
output: process.stdout
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
return new Promise((resolve) => {
|
|
892
|
+
const choices = options.choices ? ` [${options.choices.join('/')}]` : '';
|
|
893
|
+
const defaultValue = options.default !== undefined ? ` (default: ${options.default})` : '';
|
|
894
|
+
const required = options.required ? '*' : '';
|
|
895
|
+
|
|
896
|
+
rl.question(`\u001b[34m${question}${required}${choices}${defaultValue}:\u001b[0m `, (input) => {
|
|
897
|
+
let value = input.trim() || options.default;
|
|
898
|
+
|
|
899
|
+
if (options.required && !value) {
|
|
900
|
+
console.log('\u001b[31mThis field is required!\u001b[0m');
|
|
901
|
+
rl.close();
|
|
902
|
+
resolve(null);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
if (options.choices && value && !options.choices.includes(value)) {
|
|
907
|
+
console.log(`\u001b[31mInvalid choice. Must be one of: ${options.choices.join(', ')}\u001b[0m`);
|
|
908
|
+
rl.close();
|
|
909
|
+
resolve(null);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
if (options.type === 'number') {
|
|
914
|
+
value = parseFloat(value);
|
|
915
|
+
} else if (options.type === 'integer') {
|
|
916
|
+
value = parseInt(value, 10);
|
|
917
|
+
} else if (options.type === 'boolean') {
|
|
918
|
+
value = ['true', '1', 'yes', 'y'].includes(value.toLowerCase());
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
rl.close();
|
|
922
|
+
resolve(value);
|
|
923
|
+
});
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
|
|
884
927
|
getHelp() {
|
|
885
928
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
886
929
|
|