@reliverse/rempts 1.7.52 → 1.7.53
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/bin/libs/animate/animate-mod.d.ts +14 -0
- package/bin/libs/animate/animate-mod.js +60 -0
- package/bin/libs/anykey/anykey-mod.d.ts +12 -0
- package/bin/libs/anykey/anykey-mod.js +125 -0
- package/bin/libs/cancel/cancel.d.ts +45 -0
- package/bin/libs/cancel/cancel.js +72 -0
- package/bin/libs/confirm/confirm-alias.d.ts +2 -0
- package/bin/libs/confirm/confirm-alias.js +2 -0
- package/bin/libs/confirm/confirm-mod.d.ts +5 -0
- package/bin/libs/confirm/confirm-mod.js +179 -0
- package/bin/libs/date/date.d.ts +2 -0
- package/bin/libs/date/date.js +214 -0
- package/bin/libs/editor/editor-mod.d.ts +25 -0
- package/bin/libs/editor/editor-mod.js +1133 -0
- package/bin/libs/figures/figures-mod.d.ts +461 -0
- package/bin/libs/figures/figures-mod.js +285 -0
- package/bin/libs/group/group-mod.d.ts +33 -0
- package/bin/libs/group/group-mod.js +89 -0
- package/bin/libs/input/input-alias.d.ts +5 -0
- package/bin/libs/input/input-alias.js +4 -0
- package/bin/libs/input/input-mod.d.ts +16 -0
- package/bin/libs/input/input-mod.js +372 -0
- package/bin/libs/intro/intro-alias.d.ts +3 -0
- package/bin/libs/intro/intro-alias.js +3 -0
- package/bin/libs/intro/intro-mod.d.ts +20 -0
- package/bin/libs/intro/intro-mod.js +77 -0
- package/bin/libs/launcher/command-runner.d.ts +31 -0
- package/bin/libs/launcher/command-runner.js +229 -0
- package/bin/libs/launcher/launcher-alias.d.ts +2 -0
- package/bin/libs/launcher/launcher-alias.js +2 -0
- package/bin/libs/launcher/launcher-mod.d.ts +66 -0
- package/bin/libs/launcher/launcher-mod.js +975 -0
- package/bin/libs/launcher/launcher-types.d.ts +176 -0
- package/bin/libs/launcher/launcher-types.js +0 -0
- package/bin/libs/log/log-alias.d.ts +1 -0
- package/bin/libs/log/log-alias.js +2 -0
- package/bin/libs/msg-fmt/colors.d.ts +30 -0
- package/bin/libs/msg-fmt/colors.js +42 -0
- package/bin/libs/msg-fmt/logger.d.ts +17 -0
- package/bin/libs/msg-fmt/logger.js +103 -0
- package/bin/libs/msg-fmt/mapping.d.ts +3 -0
- package/bin/libs/msg-fmt/mapping.js +41 -0
- package/bin/libs/msg-fmt/messages.d.ts +35 -0
- package/bin/libs/msg-fmt/messages.js +305 -0
- package/bin/libs/msg-fmt/terminal.d.ts +15 -0
- package/bin/libs/msg-fmt/terminal.js +60 -0
- package/bin/libs/msg-fmt/variants.d.ts +11 -0
- package/bin/libs/msg-fmt/variants.js +52 -0
- package/bin/libs/multiselect/multiselect-alias.d.ts +2 -0
- package/bin/libs/multiselect/multiselect-alias.js +2 -0
- package/bin/libs/multiselect/multiselect-prompt.d.ts +2 -0
- package/bin/libs/multiselect/multiselect-prompt.js +340 -0
- package/bin/libs/next-steps/next-steps.d.ts +13 -0
- package/bin/libs/next-steps/next-steps.js +24 -0
- package/bin/libs/number/number-mod.d.ts +28 -0
- package/bin/libs/number/number-mod.js +194 -0
- package/bin/libs/outro/outro-alias.d.ts +3 -0
- package/bin/libs/outro/outro-alias.js +3 -0
- package/bin/libs/outro/outro-mod.d.ts +8 -0
- package/bin/libs/outro/outro-mod.js +55 -0
- package/bin/libs/reliarg/reliarg-mod.d.ts +76 -0
- package/bin/libs/reliarg/reliarg-mod.js +276 -0
- package/bin/libs/results/results.d.ts +7 -0
- package/bin/libs/results/results.js +27 -0
- package/bin/libs/select/nummultiselect-prompt.d.ts +6 -0
- package/bin/libs/select/nummultiselect-prompt.js +101 -0
- package/bin/libs/select/numselect-prompt.d.ts +7 -0
- package/bin/libs/select/numselect-prompt.js +111 -0
- package/bin/libs/select/select-alias.d.ts +9 -0
- package/bin/libs/select/select-alias.js +9 -0
- package/bin/libs/select/select-prompt.d.ts +5 -0
- package/bin/libs/select/select-prompt.js +308 -0
- package/bin/libs/select/toggle-prompt.d.ts +5 -0
- package/bin/libs/select/toggle-prompt.js +207 -0
- package/bin/libs/spinner/spinner-alias.d.ts +2 -0
- package/bin/libs/spinner/spinner-alias.js +2 -0
- package/bin/libs/spinner/spinner-mod.d.ts +106 -0
- package/bin/libs/spinner/spinner-mod.js +255 -0
- package/bin/libs/task/progress.d.ts +2 -0
- package/bin/libs/task/progress.js +57 -0
- package/bin/libs/task/task-spin.d.ts +15 -0
- package/bin/libs/task/task-spin.js +106 -0
- package/bin/libs/utils/colorize.d.ts +2 -0
- package/bin/libs/utils/colorize.js +122 -0
- package/bin/libs/utils/errors.d.ts +1 -0
- package/bin/libs/utils/errors.js +17 -0
- package/bin/libs/utils/prevent.d.ts +8 -0
- package/bin/libs/utils/prevent.js +62 -0
- package/bin/libs/utils/prompt-end.d.ts +8 -0
- package/bin/libs/utils/prompt-end.js +34 -0
- package/bin/libs/utils/stream-text.d.ts +18 -0
- package/bin/libs/utils/stream-text.js +137 -0
- package/bin/libs/utils/system.d.ts +6 -0
- package/bin/libs/utils/system.js +7 -0
- package/bin/libs/utils/validate.d.ts +21 -0
- package/bin/libs/utils/validate.js +17 -0
- package/bin/libs/visual/visual-mod.d.ts +6 -0
- package/bin/libs/visual/visual-mod.js +13 -0
- package/bin/mod.d.ts +53 -0
- package/bin/mod.js +107 -0
- package/bin/types.d.ts +371 -0
- package/bin/types.js +0 -0
- package/package.json +34 -59
- package/dist-npm/bin/mod.d.mts +0 -1753
- package/dist-npm/bin/mod.mjs +0 -6779
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options passed to the ReliArgParser.
|
|
3
|
+
*/
|
|
4
|
+
export type ReliArgParserOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* A list of flags that should be treated as booleans.
|
|
7
|
+
*/
|
|
8
|
+
boolean?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Whether to print a warning if an unknown flag is encountered.
|
|
11
|
+
*/
|
|
12
|
+
warnOnUnknown?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether encountering an unknown flag should cause a thrown error.
|
|
15
|
+
*/
|
|
16
|
+
strict?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* An object that maps a flag to one or more aliases (e.g. { force: "f" } or { f: ["force", "fast"] }).
|
|
19
|
+
*/
|
|
20
|
+
alias?: Record<string, string | string[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Default values for flags (e.g. { force: false, count: 0 }).
|
|
23
|
+
*/
|
|
24
|
+
defaults?: Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* If true, allows --no-foo to set foo=false (negated booleans).
|
|
27
|
+
* Defaults to `true`.
|
|
28
|
+
*/
|
|
29
|
+
negatedBoolean?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* A callback to determine if a flag is considered "unknown."
|
|
32
|
+
* If it returns false, the parser may warn or throw, depending on config.
|
|
33
|
+
*/
|
|
34
|
+
unknown?: (flagName: string) => boolean;
|
|
35
|
+
/**
|
|
36
|
+
* If true, attempt to parse non-boolean string values as numbers when possible.
|
|
37
|
+
* Defaults to false.
|
|
38
|
+
*/
|
|
39
|
+
parseNumbers?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* If true, negative numbers like -123 will not be treated as short flags
|
|
42
|
+
* and will be parsed as positional values.
|
|
43
|
+
* Defaults to true (commonly desired).
|
|
44
|
+
*/
|
|
45
|
+
allowNegativeNumbers?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* If true, stop parsing flags at the first positional argument,
|
|
48
|
+
* pushing all subsequent arguments into result._.
|
|
49
|
+
* Defaults to false.
|
|
50
|
+
*/
|
|
51
|
+
stopEarly?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* A list of flags that should be collected as arrays if repeated.
|
|
54
|
+
* e.g. { array: ["include"] } => --include file1 --include file2
|
|
55
|
+
* results in { include: ["file1", "file2"] }
|
|
56
|
+
*/
|
|
57
|
+
array?: string[];
|
|
58
|
+
/**
|
|
59
|
+
* A list of flags that should always be treated as strings (ignoring parseNumbers).
|
|
60
|
+
*/
|
|
61
|
+
string?: string[];
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The result of parsing command-line arguments.
|
|
65
|
+
*/
|
|
66
|
+
export type ReliArgParserResult = {
|
|
67
|
+
/**
|
|
68
|
+
* Positional arguments (non-flag arguments).
|
|
69
|
+
*/
|
|
70
|
+
_: string[];
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Parse arguments according to the provided `ReliArgParserOptions`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function reliArgParser(argv: string[], opts?: ReliArgParserOptions): ReliArgParserResult;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
const NEGATIVE_NUMBER_REGEX = /^[0-9]+(\.[0-9]+)?$/;
|
|
2
|
+
function isAsciiLetter(ch) {
|
|
3
|
+
const code = ch.charCodeAt(0);
|
|
4
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
5
|
+
}
|
|
6
|
+
export function reliArgParser(argv, opts = {}) {
|
|
7
|
+
const context = createParserContext(opts);
|
|
8
|
+
prePopulateDefaults(context);
|
|
9
|
+
let i = 0;
|
|
10
|
+
const argvLength = argv.length;
|
|
11
|
+
while (i < argvLength) {
|
|
12
|
+
const arg = argv[i];
|
|
13
|
+
if (!arg) {
|
|
14
|
+
i++;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (context.stopEarlyTriggered) {
|
|
18
|
+
context.result._.push(arg);
|
|
19
|
+
i++;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (arg === "--") {
|
|
23
|
+
context.result._.push(...argv.slice(i + 1));
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
if (context.allowNegativeNumbers && isNegativeNumber(arg)) {
|
|
27
|
+
if (context.stopEarly) {
|
|
28
|
+
context.result._.push(...argv.slice(i));
|
|
29
|
+
break;
|
|
30
|
+
} else {
|
|
31
|
+
context.result._.push(arg);
|
|
32
|
+
i++;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (shouldHandleNegatedBoolean(arg, context)) {
|
|
37
|
+
handleNegatedBooleanFlag(arg, context);
|
|
38
|
+
i++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] === "-") {
|
|
42
|
+
i = handleLongFlag(argv, i, context);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (arg.length > 1 && arg[0] === "-" && arg[1] !== "-") {
|
|
46
|
+
i = handleShortFlags(argv, i, context);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (context.stopEarly) {
|
|
50
|
+
context.result._.push(...argv.slice(i));
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
context.result._.push(arg);
|
|
54
|
+
i++;
|
|
55
|
+
}
|
|
56
|
+
return context.result;
|
|
57
|
+
}
|
|
58
|
+
function createParserContext(opts) {
|
|
59
|
+
const booleanFlags = new Set(opts.boolean || []);
|
|
60
|
+
const arrayFlags = new Set(opts.array || []);
|
|
61
|
+
const stringFlags = new Set(opts.string || []);
|
|
62
|
+
const aliasMap = buildAliasMap(opts.alias || {});
|
|
63
|
+
const result = { _: [] };
|
|
64
|
+
return {
|
|
65
|
+
result,
|
|
66
|
+
booleanFlags,
|
|
67
|
+
arrayFlags,
|
|
68
|
+
stringFlags,
|
|
69
|
+
aliasMap,
|
|
70
|
+
options: opts,
|
|
71
|
+
stopEarlyTriggered: false,
|
|
72
|
+
// Cache frequently accessed options for performance
|
|
73
|
+
allowNegativeNumbers: opts.allowNegativeNumbers !== false,
|
|
74
|
+
negatedBoolean: opts.negatedBoolean !== false,
|
|
75
|
+
parseNumbers: opts.parseNumbers || false,
|
|
76
|
+
stopEarly: opts.stopEarly || false,
|
|
77
|
+
warnOnUnknown: opts.warnOnUnknown || false,
|
|
78
|
+
strict: opts.strict || false
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function prePopulateDefaults(context) {
|
|
82
|
+
const { defaults = {} } = context.options;
|
|
83
|
+
for (const [key, val] of Object.entries(defaults)) {
|
|
84
|
+
context.result[key] = val;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function buildAliasMap(aliasObj) {
|
|
88
|
+
const map = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const [key, value] of Object.entries(aliasObj)) {
|
|
90
|
+
if (Array.isArray(value)) {
|
|
91
|
+
const canonical = value[0];
|
|
92
|
+
if (canonical) {
|
|
93
|
+
map.set(key, canonical);
|
|
94
|
+
for (const alias of value) {
|
|
95
|
+
map.set(alias, canonical);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
map.set(key, value);
|
|
100
|
+
map.set(value, value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return map;
|
|
104
|
+
}
|
|
105
|
+
function isNegativeNumber(arg) {
|
|
106
|
+
if (arg.length < 2 || arg[0] !== "-") return false;
|
|
107
|
+
if (arg[1] === "-") return false;
|
|
108
|
+
return NEGATIVE_NUMBER_REGEX.test(arg.slice(1));
|
|
109
|
+
}
|
|
110
|
+
function shouldHandleNegatedBoolean(arg, context) {
|
|
111
|
+
return context.negatedBoolean && arg.length > 5 && arg[0] === "-" && arg[1] === "-" && arg[2] === "n" && arg[3] === "o" && arg[4] === "-";
|
|
112
|
+
}
|
|
113
|
+
function handleNegatedBooleanFlag(arg, context) {
|
|
114
|
+
const flagName = arg.slice(5);
|
|
115
|
+
const resolvedName = resolveFlagName(flagName, context);
|
|
116
|
+
if (context.booleanFlags.has(resolvedName)) {
|
|
117
|
+
setFlagValue(resolvedName, false, context);
|
|
118
|
+
} else {
|
|
119
|
+
handleUnknownFlag(resolvedName, context);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function handleLongFlag(argv, index, context) {
|
|
123
|
+
const arg = argv[index];
|
|
124
|
+
if (arg === void 0) {
|
|
125
|
+
return index + 1;
|
|
126
|
+
}
|
|
127
|
+
const flagBody = arg.slice(2);
|
|
128
|
+
const eqIndex = flagBody.indexOf("=");
|
|
129
|
+
let rawFlagName = flagBody;
|
|
130
|
+
let value = true;
|
|
131
|
+
let nextIndex = index;
|
|
132
|
+
if (eqIndex !== -1) {
|
|
133
|
+
rawFlagName = flagBody.slice(0, eqIndex);
|
|
134
|
+
value = flagBody.slice(eqIndex + 1);
|
|
135
|
+
} else {
|
|
136
|
+
const nextArg = argv[index + 1];
|
|
137
|
+
if (nextArg && nextArg.length > 0 && nextArg[0] !== "-") {
|
|
138
|
+
value = nextArg;
|
|
139
|
+
nextIndex++;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const flagName = resolveFlagName(rawFlagName, context);
|
|
143
|
+
const parsedValue = parseValue(value, flagName, context);
|
|
144
|
+
setFlagValue(flagName, parsedValue, context);
|
|
145
|
+
validateOrWarn(flagName, context);
|
|
146
|
+
return nextIndex + 1;
|
|
147
|
+
}
|
|
148
|
+
function handleShortFlags(argv, index, context) {
|
|
149
|
+
const arg = argv[index];
|
|
150
|
+
if (arg === void 0) {
|
|
151
|
+
return index + 1;
|
|
152
|
+
}
|
|
153
|
+
const shortFlags = arg.slice(1);
|
|
154
|
+
const booleanFlags = context.booleanFlags;
|
|
155
|
+
const aliasMap = context.aliasMap;
|
|
156
|
+
const shortFlagsLength = shortFlags.length;
|
|
157
|
+
let j = 0;
|
|
158
|
+
while (j < shortFlagsLength) {
|
|
159
|
+
const flagChar = shortFlags[j];
|
|
160
|
+
if (!flagChar) {
|
|
161
|
+
j++;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const resolvedName = aliasMap.get(flagChar) || flagChar;
|
|
165
|
+
const nextChar = shortFlags[j + 1];
|
|
166
|
+
if (booleanFlags.has(resolvedName)) {
|
|
167
|
+
if (nextChar === "=") {
|
|
168
|
+
const attachedValue = shortFlags.slice(j + 2);
|
|
169
|
+
const parsed = parseValue(attachedValue, resolvedName, context);
|
|
170
|
+
setFlagValue(resolvedName, parsed, context);
|
|
171
|
+
j = shortFlagsLength;
|
|
172
|
+
} else if (nextChar && !isAsciiLetter(nextChar)) {
|
|
173
|
+
const attachedValue = shortFlags.slice(j + 1);
|
|
174
|
+
const parsed = parseValue(attachedValue, resolvedName, context);
|
|
175
|
+
setFlagValue(resolvedName, parsed, context);
|
|
176
|
+
j = shortFlagsLength;
|
|
177
|
+
} else {
|
|
178
|
+
setFlagValue(resolvedName, true, context);
|
|
179
|
+
j++;
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
const remainder = shortFlags.slice(j + 1);
|
|
183
|
+
if (remainder.startsWith("=")) {
|
|
184
|
+
const val = remainder.slice(1);
|
|
185
|
+
const parsedVal = parseValue(val, resolvedName, context);
|
|
186
|
+
setFlagValue(resolvedName, parsedVal, context);
|
|
187
|
+
validateOrWarn(resolvedName, context);
|
|
188
|
+
j = shortFlagsLength;
|
|
189
|
+
} else if (remainder.length > 0) {
|
|
190
|
+
const parsedVal = parseValue(remainder, resolvedName, context);
|
|
191
|
+
setFlagValue(resolvedName, parsedVal, context);
|
|
192
|
+
validateOrWarn(resolvedName, context);
|
|
193
|
+
j = shortFlagsLength;
|
|
194
|
+
} else {
|
|
195
|
+
const nextArgIndex = index + 1;
|
|
196
|
+
if (nextArgIndex < argv.length) {
|
|
197
|
+
const nextArg = argv[nextArgIndex];
|
|
198
|
+
if (nextArg && nextArg.length > 0 && nextArg[0] !== "-") {
|
|
199
|
+
const parsedVal = parseValue(nextArg, resolvedName, context);
|
|
200
|
+
setFlagValue(resolvedName, parsedVal, context);
|
|
201
|
+
validateOrWarn(resolvedName, context);
|
|
202
|
+
return index + 2;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
setFlagValue(resolvedName, true, context);
|
|
206
|
+
validateOrWarn(resolvedName, context);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return index + 1;
|
|
212
|
+
}
|
|
213
|
+
function resolveFlagName(rawName, context) {
|
|
214
|
+
return context.aliasMap.get(rawName) || rawName;
|
|
215
|
+
}
|
|
216
|
+
function setFlagValue(flagName, value, context) {
|
|
217
|
+
if (context.arrayFlags.has(flagName)) {
|
|
218
|
+
if (!Array.isArray(context.result[flagName])) {
|
|
219
|
+
context.result[flagName] = [];
|
|
220
|
+
}
|
|
221
|
+
context.result[flagName].push(value);
|
|
222
|
+
} else {
|
|
223
|
+
context.result[flagName] = value;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function parseValue(val, flagName, context) {
|
|
227
|
+
if (typeof val === "boolean") {
|
|
228
|
+
return val;
|
|
229
|
+
}
|
|
230
|
+
const strVal = String(val);
|
|
231
|
+
if (context.stringFlags.has(flagName)) {
|
|
232
|
+
return strVal;
|
|
233
|
+
}
|
|
234
|
+
if (context.booleanFlags.has(flagName)) {
|
|
235
|
+
if (strVal === "true") return true;
|
|
236
|
+
if (strVal === "false") return false;
|
|
237
|
+
return strVal;
|
|
238
|
+
}
|
|
239
|
+
if (context.parseNumbers && strVal.length > 0) {
|
|
240
|
+
const firstChar = strVal.charAt(0);
|
|
241
|
+
const lastChar = strVal.charAt(strVal.length - 1);
|
|
242
|
+
if (firstChar >= "0" && firstChar <= "9" || firstChar === "-" || firstChar === "+") {
|
|
243
|
+
if (lastChar >= "0" && lastChar <= "9") {
|
|
244
|
+
const maybeNum = Number(strVal);
|
|
245
|
+
if (!Number.isNaN(maybeNum)) {
|
|
246
|
+
return maybeNum;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return strVal;
|
|
252
|
+
}
|
|
253
|
+
function validateOrWarn(flagName, context) {
|
|
254
|
+
const { unknown, defaults } = context.options;
|
|
255
|
+
if (unknown) {
|
|
256
|
+
if (!unknown(flagName)) {
|
|
257
|
+
handleUnknownFlag(flagName, context);
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (context.booleanFlags.has(flagName) || context.arrayFlags.has(flagName) || context.stringFlags.has(flagName) || context.aliasMap.has(flagName)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (defaults && Object.hasOwn(defaults, flagName)) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
handleUnknownFlag(flagName, context);
|
|
268
|
+
}
|
|
269
|
+
function handleUnknownFlag(flagName, context) {
|
|
270
|
+
if (context.strict) {
|
|
271
|
+
throw new Error(`Unknown flag: --${flagName}`);
|
|
272
|
+
}
|
|
273
|
+
if (context.warnOnUnknown) {
|
|
274
|
+
console.warn(`Unknown flag: --${flagName}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
2
|
+
export async function resultPrompt({
|
|
3
|
+
results,
|
|
4
|
+
inline = true
|
|
5
|
+
}) {
|
|
6
|
+
const title = "Your input results:";
|
|
7
|
+
if (inline) {
|
|
8
|
+
const formattedResults = Object.entries(results).map(([key, value]) => `${key}: ${value}`).join(", ");
|
|
9
|
+
msg({
|
|
10
|
+
type: "M_INFO",
|
|
11
|
+
title,
|
|
12
|
+
content: formattedResults,
|
|
13
|
+
titleColor: "cyan",
|
|
14
|
+
contentColor: "dim",
|
|
15
|
+
wrapContent: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
const formattedResults = JSON.stringify(results, null, 2);
|
|
19
|
+
msg({
|
|
20
|
+
type: "M_INFO",
|
|
21
|
+
title,
|
|
22
|
+
content: formattedResults,
|
|
23
|
+
titleColor: "cyan",
|
|
24
|
+
contentColor: "dim"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
+
import readline from "node:readline/promises";
|
|
3
|
+
import { re } from "@reliverse/relico";
|
|
4
|
+
import { bar, fmt, msg } from "../msg-fmt/messages.js";
|
|
5
|
+
import { countLines, deleteLastLine, deleteLastLines } from "../msg-fmt/terminal.js";
|
|
6
|
+
export async function numMultiSelectPrompt(opts) {
|
|
7
|
+
const {
|
|
8
|
+
title = "",
|
|
9
|
+
choices,
|
|
10
|
+
defaultValue,
|
|
11
|
+
titleColor = "cyan",
|
|
12
|
+
titleTypography = "none",
|
|
13
|
+
titleVariant,
|
|
14
|
+
hint,
|
|
15
|
+
hintPlaceholderColor = "blue",
|
|
16
|
+
content,
|
|
17
|
+
contentColor = "dim",
|
|
18
|
+
contentTypography = "italic",
|
|
19
|
+
contentVariant,
|
|
20
|
+
borderColor = "dim",
|
|
21
|
+
variantOptions
|
|
22
|
+
} = opts;
|
|
23
|
+
if (!choices || choices.length === 0) {
|
|
24
|
+
throw new Error("Choices are required for multiselect prompt.");
|
|
25
|
+
}
|
|
26
|
+
const rl = readline.createInterface({ input, output });
|
|
27
|
+
const formattedBar = bar({ borderColor });
|
|
28
|
+
let linesToDelete = 0;
|
|
29
|
+
let errorMessage = "";
|
|
30
|
+
try {
|
|
31
|
+
while (true) {
|
|
32
|
+
if (linesToDelete > 0) {
|
|
33
|
+
deleteLastLines(linesToDelete);
|
|
34
|
+
}
|
|
35
|
+
const { text: question } = fmt({
|
|
36
|
+
hintPlaceholderColor,
|
|
37
|
+
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
38
|
+
title: `${title}${defaultValue ? ` [Default: ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}]` : ""}`,
|
|
39
|
+
titleColor,
|
|
40
|
+
titleTypography,
|
|
41
|
+
titleVariant: titleVariant ?? "none",
|
|
42
|
+
content: content ?? "",
|
|
43
|
+
contentColor: contentColor ?? "dim",
|
|
44
|
+
contentTypography: contentTypography ?? "none",
|
|
45
|
+
contentVariant: contentVariant ?? "none",
|
|
46
|
+
borderColor,
|
|
47
|
+
hint: hint ?? "",
|
|
48
|
+
variantOptions: variantOptions ?? {},
|
|
49
|
+
errorMessage
|
|
50
|
+
});
|
|
51
|
+
const choicesText = choices.map(
|
|
52
|
+
(choice, index) => re.dim(
|
|
53
|
+
`${formattedBar} ${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
|
|
54
|
+
)
|
|
55
|
+
).join("\n");
|
|
56
|
+
const fullPrompt = `${question}
|
|
57
|
+
${choicesText}
|
|
58
|
+
${formattedBar} ${re.bold(re.blue(`Enter your choices (comma-separated numbers between 1-${choices.length})`))}:
|
|
59
|
+
${formattedBar} `;
|
|
60
|
+
const { text: formattedPrompt } = fmt({
|
|
61
|
+
hintPlaceholderColor,
|
|
62
|
+
type: "M_NULL",
|
|
63
|
+
title: fullPrompt
|
|
64
|
+
});
|
|
65
|
+
const questionLines = countLines(formattedPrompt);
|
|
66
|
+
linesToDelete = questionLines + 1;
|
|
67
|
+
const answer = (await rl.question(`${formattedPrompt} `)).trim();
|
|
68
|
+
if (!answer && defaultValue !== void 0) {
|
|
69
|
+
deleteLastLine();
|
|
70
|
+
msg({
|
|
71
|
+
type: "M_MIDDLE",
|
|
72
|
+
title: ` ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}`,
|
|
73
|
+
titleColor: "none"
|
|
74
|
+
});
|
|
75
|
+
msg({ type: "M_BAR", borderColor });
|
|
76
|
+
return defaultValue;
|
|
77
|
+
}
|
|
78
|
+
const selections = answer.split(",").map((s) => s.trim());
|
|
79
|
+
const invalidSelections = selections.filter((s) => {
|
|
80
|
+
const num = Number(s);
|
|
81
|
+
return Number.isNaN(num) || num < 1 || num > choices.length;
|
|
82
|
+
});
|
|
83
|
+
if (invalidSelections.length > 0) {
|
|
84
|
+
errorMessage = `Invalid selections: ${invalidSelections.join(
|
|
85
|
+
", "
|
|
86
|
+
)}. Please enter numbers between 1 and ${choices.length}.`;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const selectedValues = selections.map((s) => choices[Number(s) - 1]?.id);
|
|
90
|
+
const isValid = true;
|
|
91
|
+
errorMessage = "";
|
|
92
|
+
if (isValid) {
|
|
93
|
+
rl.close();
|
|
94
|
+
msg({ type: "M_BAR", borderColor });
|
|
95
|
+
return selectedValues;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} finally {
|
|
99
|
+
rl.close();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
+
import readline from "node:readline/promises";
|
|
3
|
+
import { bar, fmt, msg } from "../msg-fmt/messages.js";
|
|
4
|
+
import { countLines, deleteLastLine, deleteLastLines } from "../msg-fmt/terminal.js";
|
|
5
|
+
import { colorize } from "../utils/colorize.js";
|
|
6
|
+
export async function numSelectPrompt(opts) {
|
|
7
|
+
const {
|
|
8
|
+
title = "",
|
|
9
|
+
hint,
|
|
10
|
+
hintPlaceholderColor = "blue",
|
|
11
|
+
validate,
|
|
12
|
+
defaultValue,
|
|
13
|
+
titleColor = "cyan",
|
|
14
|
+
titleTypography = "none",
|
|
15
|
+
titleVariant,
|
|
16
|
+
content,
|
|
17
|
+
contentColor = "dim",
|
|
18
|
+
contentTypography = "italic",
|
|
19
|
+
contentVariant,
|
|
20
|
+
borderColor = "dim",
|
|
21
|
+
variantOptions,
|
|
22
|
+
inline = true,
|
|
23
|
+
choices
|
|
24
|
+
} = opts;
|
|
25
|
+
if (!choices || choices.length === 0) {
|
|
26
|
+
throw new Error("Choices are required for select prompt.");
|
|
27
|
+
}
|
|
28
|
+
const rl = readline.createInterface({ input, output });
|
|
29
|
+
const formattedBar = bar({ borderColor });
|
|
30
|
+
let linesToDelete = 0;
|
|
31
|
+
let errorMessage = "";
|
|
32
|
+
while (true) {
|
|
33
|
+
if (linesToDelete > 0) {
|
|
34
|
+
deleteLastLines(linesToDelete);
|
|
35
|
+
}
|
|
36
|
+
const { text: question } = fmt({
|
|
37
|
+
hintPlaceholderColor,
|
|
38
|
+
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
39
|
+
title,
|
|
40
|
+
titleColor,
|
|
41
|
+
titleTypography,
|
|
42
|
+
titleVariant,
|
|
43
|
+
content,
|
|
44
|
+
contentColor,
|
|
45
|
+
contentTypography,
|
|
46
|
+
contentVariant,
|
|
47
|
+
borderColor,
|
|
48
|
+
hint,
|
|
49
|
+
variantOptions,
|
|
50
|
+
errorMessage
|
|
51
|
+
});
|
|
52
|
+
let choicesText = "";
|
|
53
|
+
if (inline) {
|
|
54
|
+
choicesText = choices.map(
|
|
55
|
+
(choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` (${choice.description})` : ""}`
|
|
56
|
+
).join(" / ");
|
|
57
|
+
} else {
|
|
58
|
+
choicesText = choices.map(
|
|
59
|
+
(choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
|
|
60
|
+
).join(`
|
|
61
|
+
${formattedBar} `);
|
|
62
|
+
}
|
|
63
|
+
const { text: formattedPrompt } = fmt({
|
|
64
|
+
hintPlaceholderColor,
|
|
65
|
+
type: "M_NULL",
|
|
66
|
+
title: `${question}
|
|
67
|
+
${choicesText}
|
|
68
|
+
${formattedBar} ${colorize(
|
|
69
|
+
"Enter your choice:",
|
|
70
|
+
contentColor
|
|
71
|
+
)}
|
|
72
|
+
${formattedBar} `
|
|
73
|
+
});
|
|
74
|
+
const questionLines = countLines(formattedPrompt);
|
|
75
|
+
linesToDelete = questionLines + 1;
|
|
76
|
+
const prompt = await rl.question(formattedPrompt);
|
|
77
|
+
const answer = prompt.trim() || defaultValue;
|
|
78
|
+
if (!prompt.trim() && defaultValue !== void 0) {
|
|
79
|
+
deleteLastLine();
|
|
80
|
+
msg({
|
|
81
|
+
type: "M_MIDDLE",
|
|
82
|
+
title: ` ${defaultValue}`,
|
|
83
|
+
titleColor: "none"
|
|
84
|
+
});
|
|
85
|
+
msg({ type: "M_BAR", borderColor });
|
|
86
|
+
}
|
|
87
|
+
const num = Number(answer);
|
|
88
|
+
if (Number.isNaN(num) || num < 1 || num > choices.length) {
|
|
89
|
+
errorMessage = `Please enter a number between 1 and ${choices.length}.`;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const selectedChoice = choices[num - 1];
|
|
93
|
+
const selectedValue = selectedChoice?.id ?? num;
|
|
94
|
+
let isValid = true;
|
|
95
|
+
errorMessage = "";
|
|
96
|
+
if (validate && isValid) {
|
|
97
|
+
const validation = await validate(selectedValue);
|
|
98
|
+
if (validation !== true) {
|
|
99
|
+
isValid = false;
|
|
100
|
+
errorMessage = typeof validation === "string" ? validation : "Invalid input.";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (isValid) {
|
|
104
|
+
rl.close();
|
|
105
|
+
if (selectedChoice?.action) {
|
|
106
|
+
await selectedChoice.action();
|
|
107
|
+
}
|
|
108
|
+
return selectedValue;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SelectPromptParams } from "../../types";
|
|
2
|
+
export declare const select: <T extends string>(params: SelectPromptParams<T>) => Promise<T>;
|
|
3
|
+
export declare const selectSimple: <T extends string>(params: Omit<SelectPromptParams<T>, "options"> & {
|
|
4
|
+
options: {
|
|
5
|
+
value: T;
|
|
6
|
+
label?: string;
|
|
7
|
+
hint?: string;
|
|
8
|
+
}[];
|
|
9
|
+
}) => Promise<T>;
|