@vexify-org/yaggs 6.6.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 CHANGED
@@ -152,6 +152,15 @@ class Yaggs {
152
152
  return this;
153
153
  }
154
154
 
155
+ async countdown(seconds, message = 'Countdown') {
156
+ await this.parser.countdown(seconds, message);
157
+ return this;
158
+ }
159
+
160
+ async ask(question, options = {}) {
161
+ return this.parser.ask(question, options);
162
+ }
163
+
155
164
  check(fn) {
156
165
  this.middleware(fn);
157
166
  return this;
package/lib/parser.js CHANGED
@@ -863,6 +863,67 @@ complete -c ${this.scriptName} `;
863
863
  this.log(message, 'success');
864
864
  }
865
865
 
866
+ countdown(seconds, message = 'Countdown') {
867
+ let remaining = seconds;
868
+
869
+ return new Promise((resolve) => {
870
+ const timer = setInterval(() => {
871
+ process.stdout.write(`\r\u001b[33m${message}: ${remaining} seconds remaining...\u001b[0m`);
872
+
873
+ remaining--;
874
+
875
+ if (remaining <= 0) {
876
+ clearInterval(timer);
877
+ process.stdout.write('\n');
878
+ resolve();
879
+ }
880
+ }, 1000);
881
+ });
882
+ }
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
+
866
927
  getHelp() {
867
928
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
868
929
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.6.0",
3
+ "version": "6.8.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {