@reliverse/rempts 1.7.3 β 1.7.5
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/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# rempts β’ powerful js/ts cli builder
|
|
1
|
+
# π rempts β’ powerful js/ts cli builder
|
|
2
2
|
|
|
3
3
|
> @reliverse/rempts is a modern, type-safe toolkit for building delightful cli experiences. it's fast, flexible, and made for developer happiness. file-based commands keep things simpleβno clutter, just clean and easy workflows. this is how cli should feel.
|
|
4
4
|
|
|
@@ -6,20 +6,25 @@
|
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- π«
|
|
10
|
-
- β¨
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- ποΈ
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
9
|
+
- π« rempts keeps you from fighting with your CLI tool
|
|
10
|
+
- β¨ rempts is your end-to-end CLI UI + command framework
|
|
11
|
+
- πΏ multi-level file-based subcommands (sibling + nested)
|
|
12
|
+
- πͺ built for DX precision and high-context terminal UX
|
|
13
|
+
- ποΈ prompt engine that *feels* modern β and actually is
|
|
14
|
+
- π file-based commands (app-router style by default)
|
|
15
|
+
- π looks great in plain scripts or full CLI apps
|
|
16
|
+
- π§ type-safe from args to prompts
|
|
17
|
+
- β‘ blazing-fast, zero runtime baggage
|
|
18
|
+
- π§© router + argument parser built-in
|
|
19
|
+
- π¨ customizable themes and styled output
|
|
20
|
+
- π¦ built-in output formatter and logger
|
|
21
|
+
- π¨ crash-safe (Ctrl+C, SIGINT, errors)
|
|
22
|
+
- π smart layout for small terminals
|
|
23
|
+
- ποΈ override styles via prompt options
|
|
24
|
+
- πͺ minimal API surface, maximum expressiveness
|
|
25
|
+
- π§ͺ scriptable for testing, stable for production
|
|
26
|
+
- ποΈ no more hacking together `inquirer`/`citty`/`commander`/`chalk`
|
|
27
|
+
- π automatic command creation (`bun dler rempts init --cmd my-cmd`)
|
|
23
28
|
|
|
24
29
|
## Installation
|
|
25
30
|
|
|
@@ -30,9 +35,9 @@ bun add @reliverse/rempts
|
|
|
30
35
|
**Coming soon**:
|
|
31
36
|
|
|
32
37
|
```bash
|
|
33
|
-
bun
|
|
34
|
-
dler rempts init --cmd my-cmd-1
|
|
35
|
-
dler rempts init --cmds
|
|
38
|
+
bun add -D @reliverse/dler
|
|
39
|
+
bun dler rempts init --cmd my-cmd-1
|
|
40
|
+
bun dler rempts init --cmds
|
|
36
41
|
```
|
|
37
42
|
|
|
38
43
|
## Usage Examples
|
|
@@ -94,7 +99,7 @@ import {
|
|
|
94
99
|
|
|
95
100
|
### Notices
|
|
96
101
|
|
|
97
|
-
- `setup`/`cleanup` are now `
|
|
102
|
+
- `setup`/`cleanup` are now `onCmdInit`/`onCmdExit` (old names still work for now).
|
|
98
103
|
|
|
99
104
|
### Prompts Usage Example
|
|
100
105
|
|
|
@@ -158,10 +163,10 @@ const main = defineCommand({
|
|
|
158
163
|
version: "1.0.0",
|
|
159
164
|
description: "Rempts Launcher Playground CLI",
|
|
160
165
|
},
|
|
161
|
-
|
|
166
|
+
onCmdInit() {
|
|
162
167
|
relinka("success", "Setup");
|
|
163
168
|
},
|
|
164
|
-
|
|
169
|
+
onCmdExit() {
|
|
165
170
|
relinka("success", "Cleanup");
|
|
166
171
|
},
|
|
167
172
|
commands: {
|
|
@@ -217,14 +222,15 @@ export default defineCommand({
|
|
|
217
222
|
- `arg-cmdName.{ts,js}`,
|
|
218
223
|
- `cmdName/index.{ts,js}`,
|
|
219
224
|
- `cmdName/cmdName-mod.{ts,js}`,
|
|
225
|
+
- **Multi-level subcommands:** `foo/bar/baz/cmd.ts` β `my-cli foo bar baz`
|
|
220
226
|
- And more β with automatic usage output.
|
|
221
227
|
|
|
222
228
|
**Hint**:
|
|
223
229
|
|
|
224
230
|
- Install `bun add -D @reliverse/dler`
|
|
225
|
-
- Use `dler rempts init --cmd cmd1 cmd2` to init commands for rempts launcher's automatically
|
|
231
|
+
- Use `bun dler rempts init --cmd cmd1 cmd2` to init commands for rempts launcher's automatically
|
|
226
232
|
|
|
227
|
-
### Advanced
|
|
233
|
+
### Advanced Launcher Usage
|
|
228
234
|
|
|
229
235
|
```ts
|
|
230
236
|
defineCommand({
|
|
@@ -247,21 +253,31 @@ defineCommand({
|
|
|
247
253
|
- Default values, validations, descriptions
|
|
248
254
|
- Full help rendering from metadata
|
|
249
255
|
|
|
250
|
-
|
|
256
|
+
**By the way! Multi-level subcommands!**
|
|
251
257
|
|
|
252
|
-
|
|
253
|
-
- Override styles via prompt options
|
|
254
|
-
- Smart layout for small terminals
|
|
255
|
-
- Looks great in plain scripts or full CLI apps
|
|
258
|
+
You can also nest subcommands arbitrarily deep:
|
|
256
259
|
|
|
257
|
-
|
|
260
|
+
```bash
|
|
261
|
+
app/
|
|
262
|
+
foo/
|
|
263
|
+
bar/
|
|
264
|
+
baz/
|
|
265
|
+
cmd.ts
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Invoke with:
|
|
258
269
|
|
|
259
270
|
```bash
|
|
260
|
-
|
|
261
|
-
rempts examples # supported options: name
|
|
271
|
+
my-cli foo bar baz --some-flag
|
|
262
272
|
```
|
|
263
273
|
|
|
264
|
-
|
|
274
|
+
The launcher will recursively traverse subfolders for each non-flag argument, loading the deepest `cmd.ts`/`cmd.js` it finds, and passing the remaining arguments to it.
|
|
275
|
+
|
|
276
|
+
See [example/launcher/app/nested](./example/launcher/app/nested/) and [example/launcher/app/sibling](./example/launcher/app/sibling/) folders to learn more.
|
|
277
|
+
|
|
278
|
+
When playing with the example, you can run e.g. `bun dev:modern nested foo bar baz` to see the result in action.
|
|
279
|
+
|
|
280
|
+
### Playground
|
|
265
281
|
|
|
266
282
|
```bash
|
|
267
283
|
git clone https://github.com/reliverse/rempts
|
|
@@ -270,8 +286,9 @@ bun i
|
|
|
270
286
|
bun dev # supported options: name
|
|
271
287
|
```
|
|
272
288
|
|
|
273
|
-
-
|
|
274
|
-
- This
|
|
289
|
+
- `bun dev:prompts`: This example will show you a `multiselectPrompt()` where you can choose which CLI prompts you want to play with.
|
|
290
|
+
- `bun dev:modern`: This example will show you a modern CLI launcher usage with file-based commands.
|
|
291
|
+
- `bun dev:classic`: This example will show you a classic CLI launcher usage with programmatic commands.
|
|
275
292
|
|
|
276
293
|
### Launcher Usage Examples
|
|
277
294
|
|
|
@@ -288,7 +305,7 @@ await runMain(defineCommand({}));
|
|
|
288
305
|
**2 Run the following:**
|
|
289
306
|
|
|
290
307
|
```bash
|
|
291
|
-
bun add -D @reliverse/dler
|
|
308
|
+
bun add -D @reliverse/dler
|
|
292
309
|
bun dler rempts init --cmd my-cmd-1 # or: dler rempts init my-cmd-1 my-cmd-2 --main src/mod.ts
|
|
293
310
|
# * `--main` is optional, default is `./src/mod.ts`
|
|
294
311
|
# * you can specify multiple commands at once
|
|
@@ -547,18 +564,18 @@ Finally, a full-featured CLI launcher without the ceremony. `@reliverse/rempts`'
|
|
|
547
564
|
- **Lifecycle Hooks:**
|
|
548
565
|
You can define optional lifecycle hooks in your main command:
|
|
549
566
|
- `onLauncherStart` and `onLauncherEnd` (global, called once per CLI process)
|
|
550
|
-
- `
|
|
567
|
+
- `onCmdInit` and `onCmdExit` (per-command, called before/after each command, but NOT for the main `run()` handler)
|
|
551
568
|
|
|
552
569
|
**Global Hooks:**
|
|
553
570
|
- `onLauncherStart`: Called once, before any command/run() is executed.
|
|
554
571
|
- `onLauncherEnd`: Called once, after all command/run() logic is finished (even if an error occurs).
|
|
555
572
|
|
|
556
573
|
**Per-Command Hooks:**
|
|
557
|
-
- `
|
|
558
|
-
- `
|
|
574
|
+
- `onCmdInit`: Called before each command (not for main `run()`).
|
|
575
|
+
- `onCmdExit`: Called after each command (not for main `run()`).
|
|
559
576
|
|
|
560
577
|
This means:
|
|
561
|
-
- If your CLI has multiple commands, `
|
|
578
|
+
- If your CLI has multiple commands, `onCmdInit` and `onCmdExit` will be called for each command invocation, not just once for the whole CLI process.
|
|
562
579
|
- If your main command has a `run()` handler (and no command is invoked), these hooks are **not** called; use the `run()` handler itself or the global hooks for such logic.
|
|
563
580
|
- This allows you to perform setup/teardown logic specific to each command execution.
|
|
564
581
|
- If you want logic to run only once for the entire CLI process, use `onLauncherStart` and `onLauncherEnd`.
|
|
@@ -569,18 +586,18 @@ Finally, a full-featured CLI launcher without the ceremony. `@reliverse/rempts`'
|
|
|
569
586
|
const main = defineCommand({
|
|
570
587
|
onLauncherStart() { relinka('info', 'Global setup (once per process)'); },
|
|
571
588
|
onLauncherEnd() { relinka('info', 'Global cleanup (once per process)'); },
|
|
572
|
-
|
|
573
|
-
|
|
589
|
+
onCmdInit() { relinka('info', 'Setup for each command'); },
|
|
590
|
+
onCmdExit() { relinka('info', 'Cleanup for each command'); },
|
|
574
591
|
commands: { ... },
|
|
575
592
|
run() { relinka('info', 'Main run handler (no command)'); },
|
|
576
593
|
});
|
|
577
594
|
// onLauncherStart/onLauncherEnd are called once per process
|
|
578
|
-
//
|
|
595
|
+
// onCmdInit/onCmdExit are called for every command (not for main run())
|
|
579
596
|
// If you want per-run() logic, use the run() handler or global hooks
|
|
580
597
|
```
|
|
581
598
|
|
|
582
599
|
- **Deprecation Notice**
|
|
583
|
-
- The legacy `setup` and `cleanup` names are still supported as aliases for per-command hooks, but will be removed in a future major version. Prefer `
|
|
600
|
+
- The legacy `setup` and `cleanup` names are still supported as aliases for per-command hooks, but will be removed in a future major version. Prefer `onCmdInit` and `onCmdExit` going forward.
|
|
584
601
|
- The `subCommands` property is deprecated as well. Please use `commands` instead. `subCommands` will be removed in a future major version.
|
|
585
602
|
|
|
586
603
|
- **Dynamic Usage Examples:**
|
|
@@ -69,17 +69,17 @@ type DefineCommandOptions<A extends ArgDefinitions = EmptyArgs> = {
|
|
|
69
69
|
/**
|
|
70
70
|
* Called before the command runs. Receives `{ args, raw }` (parsed args and raw argv).
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
onCmdInit?: CommandHook<InferArgTypes<A>>;
|
|
73
73
|
/**
|
|
74
74
|
* Called after the command finishes. Receives `{ args, raw }` (parsed args and raw argv).
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
onCmdExit?: CommandHook<InferArgTypes<A>>;
|
|
77
77
|
/**
|
|
78
|
-
* @deprecated Use
|
|
78
|
+
* @deprecated Use onCmdInit instead
|
|
79
79
|
*/
|
|
80
80
|
setup?: CommandHook<InferArgTypes<A>>;
|
|
81
81
|
/**
|
|
82
|
-
* @deprecated Use
|
|
82
|
+
* @deprecated Use onCmdExit instead
|
|
83
83
|
*/
|
|
84
84
|
cleanup?: CommandHook<InferArgTypes<A>>;
|
|
85
85
|
/**
|
|
@@ -106,17 +106,17 @@ export type Command<A extends ArgDefinitions = EmptyArgs> = {
|
|
|
106
106
|
/**
|
|
107
107
|
* Called before the command runs. Receives `{ args, raw }` (parsed args and raw argv).
|
|
108
108
|
*/
|
|
109
|
-
|
|
109
|
+
onCmdInit?: CommandHook<InferArgTypes<A>>;
|
|
110
110
|
/**
|
|
111
111
|
* Called after the command finishes. Receives `{ args, raw }` (parsed args and raw argv).
|
|
112
112
|
*/
|
|
113
|
-
|
|
113
|
+
onCmdExit?: CommandHook<InferArgTypes<A>>;
|
|
114
114
|
/**
|
|
115
|
-
* @deprecated Use
|
|
115
|
+
* @deprecated Use onCmdInit instead
|
|
116
116
|
*/
|
|
117
117
|
setup?: CommandHook<InferArgTypes<A>>;
|
|
118
118
|
/**
|
|
119
|
-
* @deprecated Use
|
|
119
|
+
* @deprecated Use onCmdExit instead
|
|
120
120
|
*/
|
|
121
121
|
cleanup?: CommandHook<InferArgTypes<A>>;
|
|
122
122
|
/**
|
|
@@ -57,8 +57,8 @@ function isFlag(str) {
|
|
|
57
57
|
return str.startsWith("-");
|
|
58
58
|
}
|
|
59
59
|
export function defineCommand(options) {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
60
|
+
const onCmdInit = options.onCmdInit || options.setup;
|
|
61
|
+
const onCmdExit = options.onCmdExit || options.cleanup;
|
|
62
62
|
const onLauncherStart = options.onLauncherStart;
|
|
63
63
|
const onLauncherEnd = options.onLauncherEnd;
|
|
64
64
|
let commands = options.commands;
|
|
@@ -70,13 +70,13 @@ export function defineCommand(options) {
|
|
|
70
70
|
args: options.args || {},
|
|
71
71
|
run: options.run,
|
|
72
72
|
commands,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
onCmdInit,
|
|
74
|
+
onCmdExit,
|
|
75
75
|
onLauncherStart,
|
|
76
76
|
onLauncherEnd,
|
|
77
77
|
// Backward-compatible aliases
|
|
78
|
-
setup:
|
|
79
|
-
cleanup:
|
|
78
|
+
setup: onCmdInit,
|
|
79
|
+
cleanup: onCmdExit
|
|
80
80
|
};
|
|
81
81
|
Object.defineProperty(cmdObj, "subCommands", {
|
|
82
82
|
get() {
|
|
@@ -335,15 +335,15 @@ This can cause recursion or unexpected behavior.`
|
|
|
335
335
|
const [subName, ...subCmdArgv] = rawArgv;
|
|
336
336
|
try {
|
|
337
337
|
const ctx = getParsedContext(command, rawArgv, parserOptions);
|
|
338
|
-
if (typeof command.
|
|
339
|
-
await command.
|
|
338
|
+
if (typeof command.onCmdInit === "function")
|
|
339
|
+
await command.onCmdInit(ctx);
|
|
340
340
|
await runFileBasedSubCmd(
|
|
341
341
|
subName,
|
|
342
342
|
subCmdArgv,
|
|
343
343
|
parserOptions.fileBasedCmds,
|
|
344
344
|
parserOptions,
|
|
345
|
-
command.
|
|
346
|
-
await command.
|
|
345
|
+
command.onCmdExit ? async (_subCtx) => {
|
|
346
|
+
await command.onCmdExit?.(ctx);
|
|
347
347
|
} : void 0
|
|
348
348
|
);
|
|
349
349
|
if (autoExit) process.exit(0);
|
|
@@ -375,14 +375,14 @@ This can cause recursion or unexpected behavior.`
|
|
|
375
375
|
if (subSpec) {
|
|
376
376
|
try {
|
|
377
377
|
const ctx = getParsedContext(command, rawArgv, parserOptions);
|
|
378
|
-
if (typeof command.
|
|
379
|
-
await command.
|
|
378
|
+
if (typeof command.onCmdInit === "function")
|
|
379
|
+
await command.onCmdInit(ctx);
|
|
380
380
|
await runSubCommand(
|
|
381
381
|
subSpec,
|
|
382
382
|
subCmdArgv,
|
|
383
383
|
parserOptions,
|
|
384
|
-
command.
|
|
385
|
-
await command.
|
|
384
|
+
command.onCmdExit ? async (_subCtx) => {
|
|
385
|
+
await command.onCmdExit?.(ctx);
|
|
386
386
|
} : void 0
|
|
387
387
|
);
|
|
388
388
|
if (autoExit) process.exit(0);
|
|
@@ -428,61 +428,67 @@ async function loadSubCommand(spec) {
|
|
|
428
428
|
throw new Error("Subcommand import did not return a valid command");
|
|
429
429
|
}
|
|
430
430
|
async function runFileBasedSubCmd(subName, argv, fileCmdOpts, parserOptions, parentFinish) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const stats = await fs.stat(subPathDir);
|
|
442
|
-
isDirCommand = stats.isDirectory();
|
|
443
|
-
}
|
|
444
|
-
if (isDirCommand) {
|
|
445
|
-
for (const pattern of possibleFiles) {
|
|
446
|
-
if (await fs.pathExists(pattern)) {
|
|
447
|
-
importPath = pattern;
|
|
448
|
-
break;
|
|
431
|
+
async function resolveCmdPath(baseDir, args) {
|
|
432
|
+
if (args.length === 0 || isFlag(args[0])) {
|
|
433
|
+
const possibleFiles2 = [
|
|
434
|
+
path.join(baseDir, "cmd.js"),
|
|
435
|
+
path.join(baseDir, "cmd.ts")
|
|
436
|
+
];
|
|
437
|
+
for (const file of possibleFiles2) {
|
|
438
|
+
if (await fs.pathExists(file)) {
|
|
439
|
+
return { importPath: file, leftoverArgv: args };
|
|
440
|
+
}
|
|
449
441
|
}
|
|
450
|
-
}
|
|
451
|
-
if (!importPath) {
|
|
452
|
-
const attempted = [subName, ...argv].join(" ");
|
|
453
|
-
const expectedPath = path.relative(
|
|
454
|
-
process.cwd(),
|
|
455
|
-
path.join(fileCmdOpts.cmdsRootPath, subName, "cmd.{ts,js}")
|
|
456
|
-
);
|
|
457
442
|
throw new Error(
|
|
458
|
-
`Unknown command or arguments: ${
|
|
443
|
+
`Unknown command or arguments: ${args.join(" ")}
|
|
459
444
|
|
|
460
|
-
Info for this CLI's developer: No valid command
|
|
445
|
+
Info for this CLI's developer: No valid command file found in ${baseDir}`
|
|
461
446
|
);
|
|
462
447
|
}
|
|
463
|
-
|
|
448
|
+
const nextDir = path.join(baseDir, args[0]);
|
|
449
|
+
if (await fs.pathExists(nextDir) && (await fs.stat(nextDir)).isDirectory()) {
|
|
450
|
+
return resolveCmdPath(nextDir, args.slice(1));
|
|
451
|
+
}
|
|
452
|
+
const possibleFiles = [
|
|
453
|
+
path.join(baseDir, "cmd.js"),
|
|
454
|
+
path.join(baseDir, "cmd.ts")
|
|
455
|
+
];
|
|
456
|
+
for (const file of possibleFiles) {
|
|
457
|
+
if (await fs.pathExists(file)) {
|
|
458
|
+
return { importPath: file, leftoverArgv: args };
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
throw new Error(
|
|
462
|
+
`Unknown command or arguments: ${args.join(" ")}
|
|
463
|
+
|
|
464
|
+
Info for this CLI's developer: No valid command file found in ${baseDir}`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
const startDir = path.join(fileCmdOpts.cmdsRootPath, subName);
|
|
468
|
+
if (!await fs.pathExists(startDir) || !(await fs.stat(startDir)).isDirectory()) {
|
|
464
469
|
const attempted = [subName, ...argv].join(" ");
|
|
465
|
-
const
|
|
470
|
+
const expectedPath = path.relative(
|
|
466
471
|
process.cwd(),
|
|
467
472
|
path.join(fileCmdOpts.cmdsRootPath, subName, "cmd.{ts,js}")
|
|
468
473
|
);
|
|
469
474
|
throw new Error(
|
|
470
475
|
`Unknown command or arguments: ${attempted}
|
|
471
476
|
|
|
472
|
-
Info for this CLI's developer: No valid command directory found, expected: ${
|
|
477
|
+
Info for this CLI's developer: No valid command directory found, expected: ${expectedPath}`
|
|
473
478
|
);
|
|
474
479
|
}
|
|
480
|
+
const { importPath, leftoverArgv } = await resolveCmdPath(startDir, argv);
|
|
475
481
|
const imported = await import(path.resolve(importPath));
|
|
476
482
|
const subCommand = imported.default;
|
|
477
483
|
if (!subCommand) {
|
|
478
484
|
throw new Error(
|
|
479
|
-
`File-based subcommand
|
|
485
|
+
`File-based subcommand has no default export or is invalid: ${importPath}`
|
|
480
486
|
);
|
|
481
487
|
}
|
|
482
488
|
try {
|
|
483
489
|
const subCtx = await runCommandWithArgs(
|
|
484
490
|
subCommand,
|
|
485
|
-
|
|
491
|
+
leftoverArgv,
|
|
486
492
|
parserOptions,
|
|
487
493
|
true
|
|
488
494
|
);
|
|
@@ -512,7 +518,9 @@ async function runCommandWithArgs(command, argv, parserOptions, returnCtx) {
|
|
|
512
518
|
);
|
|
513
519
|
const defaultMap = {};
|
|
514
520
|
for (const [argKey, def] of Object.entries(command.args || {})) {
|
|
515
|
-
if (def.
|
|
521
|
+
if (def.type === "boolean") {
|
|
522
|
+
defaultMap[argKey] = def.default !== void 0 ? def.default : false;
|
|
523
|
+
} else if (def.default !== void 0) {
|
|
516
524
|
if (def.type === "array" && typeof def.default === "string") {
|
|
517
525
|
defaultMap[argKey] = [def.default];
|
|
518
526
|
} else {
|
|
@@ -561,7 +569,11 @@ async function runCommandWithArgs(command, argv, parserOptions, returnCtx) {
|
|
|
561
569
|
else throw new Error(`Missing required argument: --${key}`);
|
|
562
570
|
}
|
|
563
571
|
try {
|
|
564
|
-
|
|
572
|
+
if (def.type === "boolean") {
|
|
573
|
+
finalArgs[key] = rawVal !== void 0 ? castArgValue(def, rawVal, key) : false;
|
|
574
|
+
} else {
|
|
575
|
+
finalArgs[key] = castArgValue(def, rawVal, key);
|
|
576
|
+
}
|
|
565
577
|
if (def.type === "array" && def.options && finalArgs[key]) {
|
|
566
578
|
const values = finalArgs[key];
|
|
567
579
|
const invalidOptions = values.filter(
|
|
@@ -663,7 +675,9 @@ export async function runCmd(command, argv = [], parserOptions = {}) {
|
|
|
663
675
|
);
|
|
664
676
|
const defaultMap = {};
|
|
665
677
|
for (const [argKey, def] of Object.entries(command.args || {})) {
|
|
666
|
-
if (def.
|
|
678
|
+
if (def.type === "boolean") {
|
|
679
|
+
defaultMap[argKey] = def.default !== void 0 ? def.default : false;
|
|
680
|
+
} else if (def.default !== void 0) {
|
|
667
681
|
if (def.type === "array" && typeof def.default === "string") {
|
|
668
682
|
defaultMap[argKey] = [def.default];
|
|
669
683
|
} else {
|
|
@@ -734,7 +748,9 @@ function getParsedContext(command, argv, parserOptions) {
|
|
|
734
748
|
);
|
|
735
749
|
const defaultMap = {};
|
|
736
750
|
for (const [argKey, def] of Object.entries(command.args || {})) {
|
|
737
|
-
if (def.
|
|
751
|
+
if (def.type === "boolean") {
|
|
752
|
+
defaultMap[argKey] = def.default !== void 0 ? def.default : false;
|
|
753
|
+
} else if (def.default !== void 0) {
|
|
738
754
|
if (def.type === "array" && typeof def.default === "string") {
|
|
739
755
|
defaultMap[argKey] = [def.default];
|
|
740
756
|
} else {
|
|
@@ -768,7 +784,11 @@ function getParsedContext(command, argv, parserOptions) {
|
|
|
768
784
|
if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
|
|
769
785
|
rawVal = [rawVal];
|
|
770
786
|
}
|
|
771
|
-
|
|
787
|
+
if (def.type === "boolean") {
|
|
788
|
+
finalArgs[key] = rawVal !== void 0 ? castArgValue(def, rawVal, key) : false;
|
|
789
|
+
} else {
|
|
790
|
+
finalArgs[key] = castArgValue(def, rawVal, key);
|
|
791
|
+
}
|
|
772
792
|
}
|
|
773
793
|
return { args: finalArgs, raw: argv };
|
|
774
794
|
}
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"name": "@reliverse/rempts",
|
|
30
30
|
"type": "module",
|
|
31
|
-
"version": "1.7.
|
|
31
|
+
"version": "1.7.5",
|
|
32
32
|
"author": "reliverse",
|
|
33
33
|
"bugs": {
|
|
34
34
|
"email": "blefnk@gmail.com",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@biomejs/biome": "1.9.4",
|
|
46
46
|
"@eslint/js": "^9.26.0",
|
|
47
|
-
"@reliverse/dler": "^1.2.
|
|
47
|
+
"@reliverse/dler": "^1.2.3",
|
|
48
48
|
"@reliverse/relidler-cfg": "^1.1.3",
|
|
49
49
|
"@stylistic/eslint-plugin": "^4.2.0",
|
|
50
50
|
"@total-typescript/ts-reset": "^0.6.1",
|