@vexify-org/yaggs 6.7.0 → 6.9.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 +8 -0
- package/lib/parser.js +69 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -157,6 +157,14 @@ class Yaggs {
|
|
|
157
157
|
return this;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
async ask(question, options = {}) {
|
|
161
|
+
return this.parser.ask(question, options);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
spinner(message = 'Loading') {
|
|
165
|
+
return this.parser.spinner(message);
|
|
166
|
+
}
|
|
167
|
+
|
|
160
168
|
check(fn) {
|
|
161
169
|
this.middleware(fn);
|
|
162
170
|
return this;
|
package/lib/parser.js
CHANGED
|
@@ -881,6 +881,75 @@ 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
|
+
|
|
927
|
+
spinner(message = 'Loading') {
|
|
928
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
929
|
+
let frameIndex = 0;
|
|
930
|
+
let interval;
|
|
931
|
+
|
|
932
|
+
const start = () => {
|
|
933
|
+
interval = setInterval(() => {
|
|
934
|
+
process.stdout.write(`\r\u001b[34m${frames[frameIndex]} ${message}\u001b[0m`);
|
|
935
|
+
frameIndex = (frameIndex + 1) % frames.length;
|
|
936
|
+
}, 80);
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
const stop = (finalMessage = '') => {
|
|
940
|
+
clearInterval(interval);
|
|
941
|
+
if (finalMessage) {
|
|
942
|
+
process.stdout.write(`\r\u001b[32m✓ ${finalMessage}\u001b[0m\n`);
|
|
943
|
+
} else {
|
|
944
|
+
process.stdout.write('\r');
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
start();
|
|
949
|
+
|
|
950
|
+
return { stop };
|
|
951
|
+
}
|
|
952
|
+
|
|
884
953
|
getHelp() {
|
|
885
954
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
886
955
|
|