@gearbox-protocol/cli-utils 5.35.0 → 5.35.1
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/dist/Zommand.d.ts +5 -2
- package/dist/Zommand.js +8 -4
- package/package.json +1 -1
package/dist/Zommand.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from "@commander-js/extra-typings";
|
|
2
2
|
import * as z4 from "zod/v4/core";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const zommandRegistry: z4.$ZodRegistry<{
|
|
4
4
|
flags: string;
|
|
5
5
|
env?: string;
|
|
6
6
|
description?: string;
|
|
@@ -8,7 +8,10 @@ export declare const zodCmdRegistry: z4.$ZodRegistry<{
|
|
|
8
8
|
export interface ZommandOptions<T extends z4.$ZodObject> {
|
|
9
9
|
schema: T;
|
|
10
10
|
templateData?: Record<string, string>;
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* If value is string, it's used as default value for config file
|
|
13
|
+
*/
|
|
14
|
+
configFile?: boolean | string;
|
|
12
15
|
}
|
|
13
16
|
export declare class Zommand<T extends z4.$ZodObject, Args extends any[] = []> extends Command<Args, z4.output<T>> {
|
|
14
17
|
#private;
|
package/dist/Zommand.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command, Option } from "@commander-js/extra-typings";
|
|
2
2
|
import * as z4 from "zod/v4/core";
|
|
3
3
|
import { resolveYamlFiles } from "./resolveYamlFiles.js";
|
|
4
|
-
export const
|
|
4
|
+
export const zommandRegistry = z4.registry();
|
|
5
5
|
export class Zommand extends Command {
|
|
6
6
|
#schema;
|
|
7
7
|
#templatedData;
|
|
@@ -15,14 +15,18 @@ export class Zommand extends Command {
|
|
|
15
15
|
throw new Error(`expected object schema, got ${this.#schema._zod.def.type}`);
|
|
16
16
|
}
|
|
17
17
|
for (const optionSchema of Object.values(def.shape)) {
|
|
18
|
-
const meta =
|
|
18
|
+
const meta = zommandRegistry.get(optionSchema);
|
|
19
19
|
if (!meta) {
|
|
20
20
|
continue;
|
|
21
21
|
}
|
|
22
22
|
this.addOption(new Option(meta.flags, meta.description));
|
|
23
23
|
}
|
|
24
24
|
if (configFile) {
|
|
25
|
-
|
|
25
|
+
let opt = new Option("--config [file]", "config file");
|
|
26
|
+
if (typeof configFile === "string") {
|
|
27
|
+
opt = opt.default(configFile);
|
|
28
|
+
}
|
|
29
|
+
this.addOption(opt);
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
action(fn) {
|
|
@@ -40,7 +44,7 @@ export class Zommand extends Command {
|
|
|
40
44
|
const def = this.#schema._zod.def;
|
|
41
45
|
const schemaFromEnv = {};
|
|
42
46
|
for (const [key, optionSchema] of Object.entries(def.shape)) {
|
|
43
|
-
const meta =
|
|
47
|
+
const meta = zommandRegistry.get(optionSchema);
|
|
44
48
|
if (meta?.env && process.env[meta.env]) {
|
|
45
49
|
schemaFromEnv[key] = process.env[meta.env];
|
|
46
50
|
}
|