@reliverse/rempts 1.6.2 → 1.7.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/LICENSE +1 -1
- package/README.md +109 -22
- package/bin/{core-impl → components}/anykey/anykey-mod.d.ts +1 -1
- package/bin/{core-impl → components}/anykey/anykey-mod.js +1 -1
- package/bin/{core-impl → components}/date/date.d.ts +1 -1
- package/bin/{core-impl → components}/editor/editor-mod.d.ts +1 -1
- package/bin/{core-impl → components}/editor/editor-mod.js +7 -7
- package/bin/{core-impl → components}/input/confirm-prompt.d.ts +1 -1
- package/bin/{core-impl → components}/input/confirm-prompt.js +1 -1
- package/bin/{core-impl → components}/input/input-prompt.d.ts +1 -1
- package/bin/{core-impl → components}/input/input-prompt.js +3 -7
- package/bin/{core-impl → components}/launcher/deprecated/_parser.ts.txt +1 -1
- package/bin/{core-impl → components}/launcher/deprecated/_utils.ts.txt +1 -1
- package/bin/{core-impl → components}/launcher/deprecated/args.ts.txt +1 -1
- package/bin/{core-impl → components}/launcher/deprecated/command.ts.txt +1 -1
- package/bin/{core-impl → components}/launcher/deprecated/launcher-mod.ts.txt +1 -1
- package/bin/{core-impl → components}/launcher/deprecated/usage.ts.txt +1 -1
- package/bin/{core-impl → components}/launcher/launcher-mod.d.ts +54 -13
- package/bin/components/launcher/launcher-mod.js +610 -0
- package/bin/{core-impl → components}/msg-fmt/colors.d.ts +1 -1
- package/bin/{core-impl → components}/msg-fmt/logger.d.ts +1 -1
- package/bin/{core-impl → components}/msg-fmt/logger.js +1 -4
- package/bin/{core-impl → components}/msg-fmt/mapping.d.ts +1 -1
- package/bin/{core-impl → components}/msg-fmt/messages.d.ts +1 -1
- package/bin/{core-impl → components}/msg-fmt/variants.d.ts +1 -1
- package/bin/{core-impl → components}/next-steps/next-steps.d.ts +2 -2
- package/bin/{core-impl → components}/number/number-mod.d.ts +1 -1
- package/bin/{core-impl → components}/select/multiselect-prompt.d.ts +1 -1
- package/bin/{core-impl → components}/select/multiselect-prompt.js +1 -1
- package/bin/{core-impl → components}/select/nummultiselect-prompt.d.ts +1 -1
- package/bin/{core-impl → components}/select/numselect-prompt.d.ts +1 -1
- package/bin/{core-impl → components}/select/numselect-prompt.js +1 -1
- package/bin/{core-impl → components}/select/select-prompt.d.ts +1 -1
- package/bin/{core-impl → components}/select/select-prompt.js +2 -2
- package/bin/{core-impl → components}/select/toggle-prompt.d.ts +1 -1
- package/bin/{core-impl → components}/select/toggle-prompt.js +1 -1
- package/bin/{core-impl → components}/st-end/end.d.ts +1 -1
- package/bin/{core-impl → components}/st-end/start.d.ts +1 -1
- package/bin/{core-impl → components}/st-end/start.js +2 -2
- package/bin/{core-impl → components}/task/progress.d.ts +1 -1
- package/bin/{core-impl → components}/visual/animate/animate.d.ts +1 -1
- package/bin/hooks/spinner/spinner-mod.d.ts +20 -0
- package/bin/hooks/spinner/spinner-mod.js +26 -0
- package/bin/mod.d.ts +37 -0
- package/bin/mod.js +88 -0
- package/bin/{core-impl/utils → utils}/colorize.d.ts +1 -1
- package/bin/{core-impl/utils → utils}/prevent.d.ts +1 -1
- package/bin/{core-impl/utils → utils}/prevent.js +2 -2
- package/bin/{core-impl/utils → utils}/prompt-end.d.ts +1 -1
- package/bin/{core-impl/utils → utils}/prompt-end.js +2 -2
- package/bin/{core-impl/utils → utils}/stream-text.d.ts +1 -1
- package/bin/{core-impl/utils → utils}/stream-text.js +2 -2
- package/package.json +46 -24
- package/bin/core-impl/figures/figures.test.d.ts +0 -1
- package/bin/core-impl/figures/figures.test.js +0 -474
- package/bin/core-impl/launcher/launcher-mod.js +0 -371
- package/bin/main.d.ts +0 -36
- package/bin/main.js +0 -86
- /package/bin/{core-impl → components}/date/date.js +0 -0
- /package/bin/{core-impl → components}/figures/figures-mod.d.ts +0 -0
- /package/bin/{core-impl → components}/figures/figures-mod.js +0 -0
- /package/bin/{core-impl → components}/msg-fmt/colors.js +0 -0
- /package/bin/{core-impl → components}/msg-fmt/mapping.js +0 -0
- /package/bin/{core-impl → components}/msg-fmt/messages.js +0 -0
- /package/bin/{core-impl → components}/msg-fmt/terminal.d.ts +0 -0
- /package/bin/{core-impl → components}/msg-fmt/terminal.js +0 -0
- /package/bin/{core-impl → components}/msg-fmt/variants.js +0 -0
- /package/bin/{core-impl → components}/next-steps/next-steps.js +0 -0
- /package/bin/{core-impl → components}/number/number-mod.js +0 -0
- /package/bin/{core-impl → components}/results/results.d.ts +0 -0
- /package/bin/{core-impl → components}/results/results.js +0 -0
- /package/bin/{core-impl → components}/select/nummultiselect-prompt.js +0 -0
- /package/bin/{core-impl → components}/st-end/end.js +0 -0
- /package/bin/{core-impl → components}/task/progress.js +0 -0
- /package/bin/{core-impl → components}/task/spinner.d.ts +0 -0
- /package/bin/{core-impl → components}/task/spinner.js +0 -0
- /package/bin/{core-impl → components}/visual/animate/animate.js +0 -0
- /package/bin/{core-impl → components}/visual/ascii-art/ascii-art.d.ts +0 -0
- /package/bin/{core-impl → components}/visual/ascii-art/ascii-art.js +0 -0
- /package/bin/{core-types.d.ts → types.d.ts} +0 -0
- /package/bin/{core-types.js → types.js} +0 -0
- /package/bin/{core-impl/utils → utils}/colorize.js +0 -0
- /package/bin/{core-impl/utils → utils}/errors.d.ts +0 -0
- /package/bin/{core-impl/utils → utils}/errors.js +0 -0
- /package/bin/{core-impl/utils → utils}/system.d.ts +0 -0
- /package/bin/{core-impl/utils → utils}/system.js +0 -0
- /package/bin/{core-impl/utils → utils}/validate.d.ts +0 -0
- /package/bin/{core-impl/utils → utils}/validate.js +0 -0
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import { reliArgParser } from "@reliverse/reliarg";
|
|
2
|
-
import { relinka, relinkaConfig, relinkaShutdown } from "@reliverse/relinka";
|
|
3
|
-
import fs from "fs-extra";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import path from "pathe";
|
|
6
|
-
const isDebugMode = process.argv.includes("--debug");
|
|
7
|
-
function debugLog(...args) {
|
|
8
|
-
if (isDebugMode) {
|
|
9
|
-
relinka("info", "[DEBUG]", ...args);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function isFlag(str) {
|
|
13
|
-
return str.startsWith("-");
|
|
14
|
-
}
|
|
15
|
-
export function defineCommand(options) {
|
|
16
|
-
return {
|
|
17
|
-
meta: options.meta,
|
|
18
|
-
args: options.args || {},
|
|
19
|
-
run: options.run,
|
|
20
|
-
subCommands: options.subCommands
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export async function showUsage(command, parserOptions = {}) {
|
|
24
|
-
relinka("info", `${command.meta.name} v${command.meta.version ?? ""}`);
|
|
25
|
-
if (command.meta.description) {
|
|
26
|
-
relinka("info", command.meta.description);
|
|
27
|
-
}
|
|
28
|
-
const fileCmds = parserOptions.fileBasedCmds;
|
|
29
|
-
if (fileCmds?.enable) {
|
|
30
|
-
const usageLine = `Usage: ${command.meta.name} <subCommand> [options]`;
|
|
31
|
-
relinka("info", usageLine);
|
|
32
|
-
try {
|
|
33
|
-
const commandsDir = path.resolve(fileCmds.cmdsRootPath);
|
|
34
|
-
const items = await fs.readdir(commandsDir, {
|
|
35
|
-
withFileTypes: true
|
|
36
|
-
});
|
|
37
|
-
const subCommandNames = [];
|
|
38
|
-
for (const dirent of items) {
|
|
39
|
-
if (dirent.isDirectory() || dirent.isFile()) {
|
|
40
|
-
const name = dirent.name.replace(/\.[jt]s$/, "");
|
|
41
|
-
try {
|
|
42
|
-
const importPath = path.join(
|
|
43
|
-
commandsDir,
|
|
44
|
-
dirent.isDirectory() ? `${name}/index.ts` : `${name}.ts`
|
|
45
|
-
);
|
|
46
|
-
const imported = await import(path.resolve(importPath));
|
|
47
|
-
if (imported.default && !imported.default.meta?.hidden) {
|
|
48
|
-
subCommandNames.push(name);
|
|
49
|
-
}
|
|
50
|
-
} catch (err) {
|
|
51
|
-
debugLog(`Skipping file ${dirent.name}:`, err);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (subCommandNames.length > 0) {
|
|
56
|
-
relinka("info", "\nAvailable file-based subCommands:");
|
|
57
|
-
subCommandNames.forEach((sc) => relinka("info", ` ${sc}`));
|
|
58
|
-
}
|
|
59
|
-
} catch (err) {
|
|
60
|
-
relinka(
|
|
61
|
-
"info",
|
|
62
|
-
`
|
|
63
|
-
(No file-based subcommands found in ${fileCmds.cmdsRootPath}.)`
|
|
64
|
-
);
|
|
65
|
-
debugLog("Error reading file-based commands:", err);
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
const subCommandNames = [];
|
|
69
|
-
if (command.subCommands) {
|
|
70
|
-
for (const [name, spec] of Object.entries(command.subCommands)) {
|
|
71
|
-
try {
|
|
72
|
-
const cmd = await loadSubCommand(spec);
|
|
73
|
-
if (!cmd?.meta?.hidden) {
|
|
74
|
-
const aliasDisplay = cmd.meta.aliases ? ` (aliases: ${cmd.meta.aliases.join(", ")})` : "";
|
|
75
|
-
subCommandNames.push(`${name}${aliasDisplay}`);
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
debugLog(`Error loading subcommand ${name}:`, err);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
let usageLine = `Usage: ${command.meta.name}`;
|
|
83
|
-
if (subCommandNames.length > 0) {
|
|
84
|
-
usageLine += " <subCommand> [options]";
|
|
85
|
-
} else {
|
|
86
|
-
usageLine += ` [options] ${renderPositional(command.args)}`;
|
|
87
|
-
}
|
|
88
|
-
relinka("info", usageLine);
|
|
89
|
-
if (subCommandNames.length > 0) {
|
|
90
|
-
relinka("info", "\nAvailable subCommands:");
|
|
91
|
-
subCommandNames.forEach((sc) => relinka("info", ` ${sc}`));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
relinka("info", "\nOptions:");
|
|
95
|
-
relinka("info", " -h, --help Show help");
|
|
96
|
-
relinka("info", " -v, --version Show version");
|
|
97
|
-
relinka("info", " --debug Enable debug mode");
|
|
98
|
-
for (const [key, def] of Object.entries(command.args || {})) {
|
|
99
|
-
if (def.type === "positional") {
|
|
100
|
-
relinka(
|
|
101
|
-
"info",
|
|
102
|
-
` <${key}> : ${def.description ?? ""} ${def.required ? "(required)" : ""}`
|
|
103
|
-
);
|
|
104
|
-
} else {
|
|
105
|
-
relinka(
|
|
106
|
-
"info",
|
|
107
|
-
` --${key} : ${def.description ?? ""} (type=${def.type})${def.required ? " (required)" : ""}${def.default !== void 0 ? ` [default: ${def.default}]` : ""}`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export async function runMain(command, parserOptions = {}) {
|
|
113
|
-
if (!parserOptions.fileBasedCmds && (!command.subCommands || Object.keys(command.subCommands).length === 0)) {
|
|
114
|
-
parserOptions.fileBasedCmds = {
|
|
115
|
-
enable: true,
|
|
116
|
-
cmdsRootPath: "src/cli/args"
|
|
117
|
-
// default path
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
const rawArgv = process.argv.slice(2);
|
|
121
|
-
const autoExit = parserOptions.autoExit !== false;
|
|
122
|
-
await relinkaConfig;
|
|
123
|
-
if (checkHelp(rawArgv)) {
|
|
124
|
-
await showUsage(command, parserOptions);
|
|
125
|
-
if (autoExit) process.exit(0);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (checkVersion(rawArgv)) {
|
|
129
|
-
relinka("info", `${command.meta.name} v${command.meta.version ?? ""}`);
|
|
130
|
-
if (autoExit) process.exit(0);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const fileBasedEnabled = parserOptions.fileBasedCmds?.enable;
|
|
134
|
-
if (fileBasedEnabled && rawArgv.length > 0 && !isFlag(rawArgv[0])) {
|
|
135
|
-
const [subName, ...subCmdArgv] = rawArgv;
|
|
136
|
-
try {
|
|
137
|
-
await runFileBasedSubCmd(
|
|
138
|
-
subName,
|
|
139
|
-
subCmdArgv,
|
|
140
|
-
parserOptions.fileBasedCmds,
|
|
141
|
-
parserOptions
|
|
142
|
-
);
|
|
143
|
-
if (autoExit) process.exit(0);
|
|
144
|
-
return;
|
|
145
|
-
} catch (err) {
|
|
146
|
-
relinka("error", "Error loading file-based subcommand:", err.message);
|
|
147
|
-
if (autoExit) process.exit(1);
|
|
148
|
-
throw err;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (!fileBasedEnabled && command.subCommands && rawArgv.length > 0 && !isFlag(rawArgv[0])) {
|
|
152
|
-
const [maybeSub, ...subCmdArgv] = rawArgv;
|
|
153
|
-
let subSpec;
|
|
154
|
-
for (const [key, spec] of Object.entries(command.subCommands)) {
|
|
155
|
-
if (key === maybeSub) {
|
|
156
|
-
subSpec = spec;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
const cmd = await loadSubCommand(spec);
|
|
161
|
-
if (cmd.meta.aliases?.includes(maybeSub)) {
|
|
162
|
-
subSpec = spec;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
} catch (err) {
|
|
166
|
-
debugLog(`Error checking alias for subcommand ${key}:`, err);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (subSpec) {
|
|
170
|
-
try {
|
|
171
|
-
await runSubCommand(subSpec, subCmdArgv, parserOptions);
|
|
172
|
-
if (autoExit) process.exit(0);
|
|
173
|
-
return;
|
|
174
|
-
} catch (err) {
|
|
175
|
-
relinka("error", "Error running subcommand:", err.message);
|
|
176
|
-
if (autoExit) process.exit(1);
|
|
177
|
-
throw err;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
await runCommandWithArgs(command, rawArgv, parserOptions);
|
|
182
|
-
await relinkaShutdown();
|
|
183
|
-
}
|
|
184
|
-
function checkHelp(argv) {
|
|
185
|
-
return argv.includes("--help") || argv.includes("-h");
|
|
186
|
-
}
|
|
187
|
-
function checkVersion(argv) {
|
|
188
|
-
return argv.includes("--version") || argv.includes("-v");
|
|
189
|
-
}
|
|
190
|
-
async function loadSubCommand(spec) {
|
|
191
|
-
if (typeof spec === "string") {
|
|
192
|
-
const mod = await import(spec);
|
|
193
|
-
if (!mod.default) {
|
|
194
|
-
throw new Error(`Subcommand module "${spec}" has no default export`);
|
|
195
|
-
}
|
|
196
|
-
return mod.default;
|
|
197
|
-
}
|
|
198
|
-
const imported = await spec();
|
|
199
|
-
if ("default" in imported && imported.default) {
|
|
200
|
-
return imported.default;
|
|
201
|
-
}
|
|
202
|
-
if (imported) {
|
|
203
|
-
return imported;
|
|
204
|
-
}
|
|
205
|
-
throw new Error("Subcommand import did not return a valid command");
|
|
206
|
-
}
|
|
207
|
-
async function runFileBasedSubCmd(subName, argv, fileCmdOpts, parserOptions) {
|
|
208
|
-
const subPathDir = path.join(fileCmdOpts.cmdsRootPath, subName);
|
|
209
|
-
let importPath;
|
|
210
|
-
const possibleFiles = [
|
|
211
|
-
// When command is inside a directory
|
|
212
|
-
path.join(subPathDir, "index.js"),
|
|
213
|
-
path.join(subPathDir, "index.ts"),
|
|
214
|
-
path.join(subPathDir, `${subName}-mod.js`),
|
|
215
|
-
path.join(subPathDir, `${subName}-mod.ts`),
|
|
216
|
-
// When command is a file in the root directory
|
|
217
|
-
path.join(fileCmdOpts.cmdsRootPath, `${subName}.js`),
|
|
218
|
-
path.join(fileCmdOpts.cmdsRootPath, `${subName}.ts`),
|
|
219
|
-
path.join(fileCmdOpts.cmdsRootPath, `arg-${subName}.js`),
|
|
220
|
-
path.join(fileCmdOpts.cmdsRootPath, `arg-${subName}.ts`)
|
|
221
|
-
];
|
|
222
|
-
const dirExists = await fs.pathExists(subPathDir);
|
|
223
|
-
let isDirCommand = false;
|
|
224
|
-
if (dirExists) {
|
|
225
|
-
const stats = await fs.stat(subPathDir);
|
|
226
|
-
isDirCommand = stats.isDirectory();
|
|
227
|
-
}
|
|
228
|
-
if (isDirCommand) {
|
|
229
|
-
for (const pattern of possibleFiles.slice(0, 4)) {
|
|
230
|
-
if (await fs.pathExists(pattern)) {
|
|
231
|
-
importPath = pattern;
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (!importPath) {
|
|
236
|
-
throw new Error(
|
|
237
|
-
`No valid command file found in directory "${subName}". Expected one of: index.{js,ts} or ${subName}-mod.{js,ts}`
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
} else {
|
|
241
|
-
for (const pattern of possibleFiles.slice(4)) {
|
|
242
|
-
if (await fs.pathExists(pattern)) {
|
|
243
|
-
importPath = pattern;
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (!importPath) {
|
|
248
|
-
throw new Error(
|
|
249
|
-
`No valid command file found for "${subName}". Expected one of: ${subName}.{js,ts} or arg-${subName}.{js,ts}`
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const imported = await import(path.resolve(importPath));
|
|
254
|
-
const subCommand = imported.default;
|
|
255
|
-
if (!subCommand) {
|
|
256
|
-
throw new Error(
|
|
257
|
-
`File-based subcommand "${subName}" has no default export or is invalid.`
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
await runCommandWithArgs(subCommand, argv, parserOptions);
|
|
261
|
-
}
|
|
262
|
-
async function runSubCommand(spec, argv, parserOptions) {
|
|
263
|
-
const subCommand = await loadSubCommand(spec);
|
|
264
|
-
await runCommandWithArgs(subCommand, argv, parserOptions);
|
|
265
|
-
}
|
|
266
|
-
async function runCommandWithArgs(command, argv, parserOptions) {
|
|
267
|
-
const autoExit = parserOptions.autoExit !== false;
|
|
268
|
-
const booleanKeys = Object.keys(command.args || {}).filter(
|
|
269
|
-
(k) => command.args[k].type === "boolean"
|
|
270
|
-
);
|
|
271
|
-
const defaultMap = {};
|
|
272
|
-
for (const [argKey, def] of Object.entries(command.args || {})) {
|
|
273
|
-
if (def.default !== void 0) {
|
|
274
|
-
defaultMap[argKey] = def.default;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
const mergedParserOptions = {
|
|
278
|
-
...parserOptions,
|
|
279
|
-
boolean: [...parserOptions.boolean || [], ...booleanKeys],
|
|
280
|
-
defaults: { ...defaultMap, ...parserOptions.defaults || {} }
|
|
281
|
-
};
|
|
282
|
-
const parsed = reliArgParser(argv, mergedParserOptions);
|
|
283
|
-
debugLog("Parsed arguments:", parsed);
|
|
284
|
-
const finalArgs = {};
|
|
285
|
-
const positionalKeys = Object.keys(command.args || {}).filter(
|
|
286
|
-
(k) => command.args[k].type === "positional"
|
|
287
|
-
);
|
|
288
|
-
const leftoverPositionals = [...parsed._ || []];
|
|
289
|
-
for (let i = 0; i < positionalKeys.length; i++) {
|
|
290
|
-
const key = positionalKeys[i];
|
|
291
|
-
const def = command.args?.[key];
|
|
292
|
-
const val = leftoverPositionals[i];
|
|
293
|
-
if (val == null && def.required) {
|
|
294
|
-
relinka("error", `Missing required positional argument: <${key}>`);
|
|
295
|
-
await showUsage(command, parserOptions);
|
|
296
|
-
if (autoExit) process.exit(1);
|
|
297
|
-
else throw new Error(`Missing required positional argument: <${key}>`);
|
|
298
|
-
}
|
|
299
|
-
finalArgs[key] = val != null ? castArgValue(def, val, key) : def.default;
|
|
300
|
-
}
|
|
301
|
-
const otherKeys = Object.keys(command.args || {}).filter(
|
|
302
|
-
(k) => command.args[k].type !== "positional"
|
|
303
|
-
);
|
|
304
|
-
for (const key of otherKeys) {
|
|
305
|
-
const def = command.args?.[key];
|
|
306
|
-
let rawVal = parsed[key];
|
|
307
|
-
if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
|
|
308
|
-
rawVal = [rawVal];
|
|
309
|
-
}
|
|
310
|
-
if (rawVal == null && def.required) {
|
|
311
|
-
relinka("error", `Missing required argument: --${key}`);
|
|
312
|
-
await showUsage(command, parserOptions);
|
|
313
|
-
if (autoExit) process.exit(1);
|
|
314
|
-
else throw new Error(`Missing required argument: --${key}`);
|
|
315
|
-
}
|
|
316
|
-
try {
|
|
317
|
-
finalArgs[key] = castArgValue(def, rawVal, key);
|
|
318
|
-
} catch (err) {
|
|
319
|
-
relinka("error", String(err));
|
|
320
|
-
if (autoExit) process.exit(1);
|
|
321
|
-
else throw err;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
const ctx = {
|
|
325
|
-
args: finalArgs,
|
|
326
|
-
raw: argv
|
|
327
|
-
};
|
|
328
|
-
try {
|
|
329
|
-
await command.run(ctx);
|
|
330
|
-
} catch (err) {
|
|
331
|
-
relinka("error", `Error while executing command:
|
|
332
|
-
${String(err)}`);
|
|
333
|
-
if (autoExit) process.exit(1);
|
|
334
|
-
else throw err;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
function castArgValue(def, rawVal, argName) {
|
|
338
|
-
if (rawVal == null) {
|
|
339
|
-
return def.default ?? void 0;
|
|
340
|
-
}
|
|
341
|
-
switch (def.type) {
|
|
342
|
-
case "boolean":
|
|
343
|
-
if (typeof rawVal === "string") {
|
|
344
|
-
const lower = rawVal.toLowerCase();
|
|
345
|
-
if (lower === "true") return true;
|
|
346
|
-
if (lower === "false") return false;
|
|
347
|
-
}
|
|
348
|
-
return Boolean(rawVal);
|
|
349
|
-
case "string":
|
|
350
|
-
return typeof rawVal === "string" ? rawVal : String(rawVal);
|
|
351
|
-
case "number": {
|
|
352
|
-
const n = Number(rawVal);
|
|
353
|
-
if (Number.isNaN(n)) {
|
|
354
|
-
throw new Error(`Invalid number provided for --${argName}: ${rawVal}`);
|
|
355
|
-
}
|
|
356
|
-
return n;
|
|
357
|
-
}
|
|
358
|
-
case "positional":
|
|
359
|
-
return String(rawVal);
|
|
360
|
-
case "array":
|
|
361
|
-
return Array.isArray(rawVal) ? rawVal : [String(rawVal)];
|
|
362
|
-
default:
|
|
363
|
-
return rawVal;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
function renderPositional(args) {
|
|
367
|
-
const positionalKeys = Object.keys(args || {}).filter(
|
|
368
|
-
(k) => args[k].type === "positional"
|
|
369
|
-
);
|
|
370
|
-
return positionalKeys.map((k) => `<${k}>`).join(" ");
|
|
371
|
-
}
|
package/bin/main.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export { anykeyPrompt } from "./core-impl/anykey/anykey-mod.js";
|
|
2
|
-
export { datePrompt } from "./core-impl/date/date.js";
|
|
3
|
-
export { startEditor } from "./core-impl/editor/editor-mod.js";
|
|
4
|
-
export { mainSymbols, fallbackSymbols, } from "./core-impl/figures/figures-mod.js";
|
|
5
|
-
export { confirmPrompt } from "./core-impl/input/confirm-prompt.js";
|
|
6
|
-
export { inputPrompt } from "./core-impl/input/input-prompt.js";
|
|
7
|
-
export type { ArgDefinition, ArgDefinitions, SubCommandsMap, Command, InferArgTypes, FileBasedCmdsOptions, } from "./core-impl/launcher/launcher-mod.js";
|
|
8
|
-
export { defineCommand, showUsage, runMain, } from "./core-impl/launcher/launcher-mod.js";
|
|
9
|
-
export { toBaseColor, toSolidColor } from "./core-impl/msg-fmt/colors.js";
|
|
10
|
-
export { relinkaByRemptsDeprecated, relinkaAsyncByRemptsDeprecated, throwError, } from "./core-impl/msg-fmt/logger.js";
|
|
11
|
-
export { colorMap, typographyMap } from "./core-impl/msg-fmt/mapping.js";
|
|
12
|
-
export { symbols, bar, fmt, msg, msgUndo, msgUndoAll, printLineBar, } from "./core-impl/msg-fmt/messages.js";
|
|
13
|
-
export { getTerminalHeight, getExactTerminalWidth, getTerminalWidth, breakLines, removeCursor, restoreCursor, deleteLastLine, deleteLastLines, countLines, } from "./core-impl/msg-fmt/terminal.js";
|
|
14
|
-
export { variantMap, isValidVariant, applyVariant, } from "./core-impl/msg-fmt/variants.js";
|
|
15
|
-
export { nextStepsPrompt } from "./core-impl/next-steps/next-steps.js";
|
|
16
|
-
export { numberPrompt } from "./core-impl/number/number-mod.js";
|
|
17
|
-
export type { ResultsType } from "./core-impl/results/results.js";
|
|
18
|
-
export { resultPrompt } from "./core-impl/results/results.js";
|
|
19
|
-
export { multiselectPrompt } from "./core-impl/select/multiselect-prompt.js";
|
|
20
|
-
export { numMultiSelectPrompt } from "./core-impl/select/nummultiselect-prompt.js";
|
|
21
|
-
export { numSelectPrompt } from "./core-impl/select/numselect-prompt.js";
|
|
22
|
-
export { selectPrompt } from "./core-impl/select/select-prompt.js";
|
|
23
|
-
export { togglePrompt } from "./core-impl/select/toggle-prompt.js";
|
|
24
|
-
export { endPrompt } from "./core-impl/st-end/end.js";
|
|
25
|
-
export { startPrompt } from "./core-impl/st-end/start.js";
|
|
26
|
-
export { progressTaskPrompt } from "./core-impl/task/progress.js";
|
|
27
|
-
export { spinnerTaskPrompt } from "./core-impl/task/spinner.js";
|
|
28
|
-
export { colorize } from "./core-impl/utils/colorize.js";
|
|
29
|
-
export { errorHandler } from "./core-impl/utils/errors.js";
|
|
30
|
-
export { preventUnsupportedTTY, preventWindowsHomeDirRoot, preventWrongTerminalSize, } from "./core-impl/utils/prevent.js";
|
|
31
|
-
export { completePrompt, renderEndLine, renderEndLineInput, } from "./core-impl/utils/prompt-end.js";
|
|
32
|
-
export { streamText, streamTextBox, streamTextWithSpinner, } from "./core-impl/utils/stream-text.js";
|
|
33
|
-
export { pm, reliversePrompts } from "./core-impl/utils/system.js";
|
|
34
|
-
export { isTerminalInteractive, isValidName, normalizeName, } from "./core-impl/utils/validate.js";
|
|
35
|
-
export { animationMap, animateText, } from "./core-impl/visual/animate/animate.js";
|
|
36
|
-
export { createAsciiArt } from "./core-impl/visual/ascii-art/ascii-art.js";
|
package/bin/main.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
export { anykeyPrompt } from "./core-impl/anykey/anykey-mod.js";
|
|
2
|
-
export { datePrompt } from "./core-impl/date/date.js";
|
|
3
|
-
export { startEditor } from "./core-impl/editor/editor-mod.js";
|
|
4
|
-
export {
|
|
5
|
-
mainSymbols,
|
|
6
|
-
fallbackSymbols
|
|
7
|
-
} from "./core-impl/figures/figures-mod.js";
|
|
8
|
-
export { confirmPrompt } from "./core-impl/input/confirm-prompt.js";
|
|
9
|
-
export { inputPrompt } from "./core-impl/input/input-prompt.js";
|
|
10
|
-
export {
|
|
11
|
-
defineCommand,
|
|
12
|
-
showUsage,
|
|
13
|
-
runMain
|
|
14
|
-
} from "./core-impl/launcher/launcher-mod.js";
|
|
15
|
-
export { toBaseColor, toSolidColor } from "./core-impl/msg-fmt/colors.js";
|
|
16
|
-
export {
|
|
17
|
-
relinkaByRemptsDeprecated,
|
|
18
|
-
relinkaAsyncByRemptsDeprecated,
|
|
19
|
-
throwError
|
|
20
|
-
} from "./core-impl/msg-fmt/logger.js";
|
|
21
|
-
export { colorMap, typographyMap } from "./core-impl/msg-fmt/mapping.js";
|
|
22
|
-
export {
|
|
23
|
-
symbols,
|
|
24
|
-
bar,
|
|
25
|
-
fmt,
|
|
26
|
-
msg,
|
|
27
|
-
msgUndo,
|
|
28
|
-
msgUndoAll,
|
|
29
|
-
printLineBar
|
|
30
|
-
} from "./core-impl/msg-fmt/messages.js";
|
|
31
|
-
export {
|
|
32
|
-
getTerminalHeight,
|
|
33
|
-
getExactTerminalWidth,
|
|
34
|
-
getTerminalWidth,
|
|
35
|
-
breakLines,
|
|
36
|
-
removeCursor,
|
|
37
|
-
restoreCursor,
|
|
38
|
-
deleteLastLine,
|
|
39
|
-
deleteLastLines,
|
|
40
|
-
countLines
|
|
41
|
-
} from "./core-impl/msg-fmt/terminal.js";
|
|
42
|
-
export {
|
|
43
|
-
variantMap,
|
|
44
|
-
isValidVariant,
|
|
45
|
-
applyVariant
|
|
46
|
-
} from "./core-impl/msg-fmt/variants.js";
|
|
47
|
-
export { nextStepsPrompt } from "./core-impl/next-steps/next-steps.js";
|
|
48
|
-
export { numberPrompt } from "./core-impl/number/number-mod.js";
|
|
49
|
-
export { resultPrompt } from "./core-impl/results/results.js";
|
|
50
|
-
export { multiselectPrompt } from "./core-impl/select/multiselect-prompt.js";
|
|
51
|
-
export { numMultiSelectPrompt } from "./core-impl/select/nummultiselect-prompt.js";
|
|
52
|
-
export { numSelectPrompt } from "./core-impl/select/numselect-prompt.js";
|
|
53
|
-
export { selectPrompt } from "./core-impl/select/select-prompt.js";
|
|
54
|
-
export { togglePrompt } from "./core-impl/select/toggle-prompt.js";
|
|
55
|
-
export { endPrompt } from "./core-impl/st-end/end.js";
|
|
56
|
-
export { startPrompt } from "./core-impl/st-end/start.js";
|
|
57
|
-
export { progressTaskPrompt } from "./core-impl/task/progress.js";
|
|
58
|
-
export { spinnerTaskPrompt } from "./core-impl/task/spinner.js";
|
|
59
|
-
export { colorize } from "./core-impl/utils/colorize.js";
|
|
60
|
-
export { errorHandler } from "./core-impl/utils/errors.js";
|
|
61
|
-
export {
|
|
62
|
-
preventUnsupportedTTY,
|
|
63
|
-
preventWindowsHomeDirRoot,
|
|
64
|
-
preventWrongTerminalSize
|
|
65
|
-
} from "./core-impl/utils/prevent.js";
|
|
66
|
-
export {
|
|
67
|
-
completePrompt,
|
|
68
|
-
renderEndLine,
|
|
69
|
-
renderEndLineInput
|
|
70
|
-
} from "./core-impl/utils/prompt-end.js";
|
|
71
|
-
export {
|
|
72
|
-
streamText,
|
|
73
|
-
streamTextBox,
|
|
74
|
-
streamTextWithSpinner
|
|
75
|
-
} from "./core-impl/utils/stream-text.js";
|
|
76
|
-
export { pm, reliversePrompts } from "./core-impl/utils/system.js";
|
|
77
|
-
export {
|
|
78
|
-
isTerminalInteractive,
|
|
79
|
-
isValidName,
|
|
80
|
-
normalizeName
|
|
81
|
-
} from "./core-impl/utils/validate.js";
|
|
82
|
-
export {
|
|
83
|
-
animationMap,
|
|
84
|
-
animateText
|
|
85
|
-
} from "./core-impl/visual/animate/animate.js";
|
|
86
|
-
export { createAsciiArt } from "./core-impl/visual/ascii-art/ascii-art.js";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|