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