@vexify-org/yaggs 6.10.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 CHANGED
@@ -169,6 +169,10 @@ 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
+
172
176
  check(fn) {
173
177
  this.middleware(fn);
174
178
  return this;
package/lib/parser.js CHANGED
@@ -976,6 +976,41 @@ 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
+
979
1014
  getHelp() {
980
1015
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
981
1016
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.10.0",
3
+ "version": "6.11.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {