@reliverse/rempts 1.7.16 โ†’ 1.7.18

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
@@ -25,7 +25,8 @@
25
25
  - ๐Ÿช„ minimal API surface, maximum expressiveness
26
26
  - ๐Ÿงช scriptable for testing, stable for production
27
27
  - ๐Ÿž๏ธ no more hacking together `inquirer`/`citty`/`commander`/`chalk`
28
- - ๐Ÿ†• automatic command creation (`bun dler rempts init --cmd my-cmd`)
28
+ - ๐Ÿ†• automatic command creation (`bun dler rempts --init cmd1 cmd2`)
29
+ - ๐Ÿฆโ€๐Ÿ”ฅ automatic creation of `src/app/cmds.ts` file (`bun dler rempts`)
29
30
 
30
31
  ## Installation
31
32
 
@@ -37,8 +38,8 @@ bun add @reliverse/rempts
37
38
 
38
39
  ```bash
39
40
  bun add -D @reliverse/dler
40
- bun dler rempts init --cmd my-cmd-1
41
- bun dler rempts init --cmds
41
+ bun dler rempts --init cmd1 cmd2 # creates `src/app/cmd1/cmd.ts` and `src/app/cmd2/cmd.ts` files
42
+ bun dler rempts # creates `src/app/cmds.ts` file
42
43
  ```
43
44
 
44
45
  ## Usage Examples
@@ -229,7 +230,7 @@ export default defineCommand({
229
230
  **Hint**:
230
231
 
231
232
  - Install `bun add -D @reliverse/dler`
232
- - Use `bun dler rempts init --cmd cmd1 cmd2` to init commands for rempts launcher's automatically
233
+ - Use `bun dler rempts --init cmd1 cmd2` to init commands for rempts launcher's automatically
233
234
 
234
235
  ### Advanced Launcher Usage
235
236
 
@@ -307,7 +308,7 @@ await runMain(defineCommand({}));
307
308
 
308
309
  ```bash
309
310
  bun add -D @reliverse/dler
310
- bun dler rempts init --cmd my-cmd-1 # or: dler rempts init my-cmd-1 my-cmd-2 --main src/mod.ts
311
+ bun dler rempts --init my-cmd-1 # or: dler rempts --init my-cmd-1 my-cmd-2 --main src/mod.ts
311
312
  # * `--main` is optional, default is `./src/mod.ts`
312
313
  # * you can specify multiple commands at once
313
314
  ```
@@ -295,7 +295,8 @@ export async function showUsage(command, parserOptions = {}) {
295
295
  def.description ?? "",
296
296
  `type=${def.type}`,
297
297
  def.default !== void 0 ? `default=${JSON.stringify(def.default)}` : null,
298
- def.required ? "required" : null
298
+ def.required ? "required" : null,
299
+ def.dependencies ? `depends on: ${def.dependencies.map((r) => `--${r}`).join(", ")}` : null
299
300
  ].filter(Boolean);
300
301
  optionItems.push({ text, desc: parts.join(" | ") });
301
302
  }
@@ -674,6 +675,23 @@ async function runCommandWithArgs(command, argv, parserOptions, returnCtx) {
674
675
  if (autoExit) process.exit(1);
675
676
  else throw new Error(`Missing required argument: --${key}`);
676
677
  }
678
+ if (def.dependencies && Array.isArray(def.dependencies)) {
679
+ for (const dependency of def.dependencies) {
680
+ const dependencyValue = parsed[dependency] ?? defaultMap[dependency];
681
+ if (!dependencyValue) {
682
+ await showUsage(command, parserOptions);
683
+ relinka(
684
+ "error",
685
+ `Argument --${key} requires --${dependency} to be set`
686
+ );
687
+ if (autoExit) process.exit(1);
688
+ else
689
+ throw new Error(
690
+ `Argument --${key} requires --${dependency} to be set`
691
+ );
692
+ }
693
+ }
694
+ }
677
695
  try {
678
696
  if (def.type === "boolean") {
679
697
  finalArgs[key] = rawVal !== void 0 ? castArgValue(def, rawVal, key) : false;
@@ -878,6 +896,16 @@ export async function runCmd(command, argv = [], parserOptions = {}) {
878
896
  if (valueOrDefault == null && def.required) {
879
897
  throw new Error(`Missing required argument: --${key}`);
880
898
  }
899
+ if (def.dependencies && Array.isArray(def.dependencies)) {
900
+ for (const dependency of def.dependencies) {
901
+ const dependencyValue = parsed[dependency] ?? defaultMap[dependency];
902
+ if (!dependencyValue) {
903
+ throw new Error(
904
+ `Argument --${key} requires --${dependency} to be set`
905
+ );
906
+ }
907
+ }
908
+ }
881
909
  try {
882
910
  if (def.type === "boolean") {
883
911
  finalArgs[key] = rawVal !== void 0 ? castArgValue(def, rawVal, key) : false;
@@ -4,28 +4,40 @@ export type BaseArgProps = {
4
4
  required?: boolean;
5
5
  allowed?: string[];
6
6
  };
7
- export type PositionalArgDefinition = {
7
+ export type BaseArgDefinition = {
8
+ type: string;
9
+ description?: string;
10
+ required?: boolean;
11
+ default?: any;
12
+ allowed?: any[];
13
+ dependencies?: string[];
14
+ };
15
+ export type PositionalArgDefinition = BaseArgDefinition & {
8
16
  type: "positional";
9
17
  default?: string;
10
- } & BaseArgProps;
11
- export type BooleanArgDefinition = {
18
+ };
19
+ export type BooleanArgDefinition = BaseArgDefinition & {
12
20
  type: "boolean";
13
21
  default?: boolean;
14
22
  allowed?: boolean[];
15
- } & BaseArgProps;
16
- export type StringArgDefinition = {
23
+ alias?: string;
24
+ };
25
+ export type StringArgDefinition = BaseArgDefinition & {
17
26
  type: "string";
18
27
  default?: string;
19
- } & BaseArgProps;
20
- export type NumberArgDefinition = {
28
+ alias?: string;
29
+ };
30
+ export type NumberArgDefinition = BaseArgDefinition & {
21
31
  type: "number";
22
32
  default?: number;
23
33
  allowed?: number[];
24
- } & BaseArgProps;
25
- export type ArrayArgDefinition = {
34
+ alias?: string;
35
+ };
36
+ export type ArrayArgDefinition = BaseArgDefinition & {
26
37
  type: "array";
27
38
  default?: string | readonly string[];
28
- } & BaseArgProps;
39
+ alias?: string;
40
+ };
29
41
  export type ArgDefinition = PositionalArgDefinition | BooleanArgDefinition | StringArgDefinition | NumberArgDefinition | ArrayArgDefinition;
30
42
  export type ArgDefinitions = Record<string, ArgDefinition>;
31
43
  export type CommandMeta = {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "@reliverse/pathkit": "^1.2.1",
5
5
  "@reliverse/reliarg": "^1.0.3",
6
6
  "@reliverse/relico": "^1.1.2",
7
- "@reliverse/relifso": "^1.3.1",
7
+ "@reliverse/relifso": "^1.4.5",
8
8
  "@reliverse/relinka": "^1.4.7",
9
9
  "@reliverse/runtime": "^1.0.3",
10
10
  "ansi-escapes": "^7.0.0",
@@ -29,7 +29,7 @@
29
29
  "license": "MIT",
30
30
  "name": "@reliverse/rempts",
31
31
  "type": "module",
32
- "version": "1.7.16",
32
+ "version": "1.7.18",
33
33
  "author": "reliverse",
34
34
  "bugs": {
35
35
  "email": "blefnk@gmail.com",