@vexify-org/yaggs 6.10.0 → 6.12.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 CHANGED
@@ -169,6 +169,14 @@ class Yaggs {
169
169
  return this.parser.confirm(message, options);
170
170
  }
171
171
 
172
+ async select(options, question = 'Select an option') {
173
+ return this.parser.select(options, question);
174
+ }
175
+
176
+ async password(message = 'Enter password') {
177
+ return this.parser.password(message);
178
+ }
179
+
172
180
  check(fn) {
173
181
  this.middleware(fn);
174
182
  return this;
package/lib/parser.js CHANGED
@@ -976,6 +976,85 @@ complete -c ${this.scriptName} `;
976
976
  });
977
977
  }
978
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
+
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
+
979
1058
  getHelp() {
980
1059
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
981
1060
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.10.0",
3
+ "version": "6.12.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {