Skip to content

Commit f7ff517

Browse files
committed
chore: let one pass a z.object
1 parent 387925a commit f7ff517

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/arg-parser/src/arg-parser.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,13 +1450,13 @@ describe('arg-parser', function () {
14501450
'--deprecatedField',
14511451
'100',
14521452
],
1453-
schema: {
1453+
schema: z.object({
14541454
extendedField: z.number(),
14551455
replacedField: z.number(),
14561456
deprecatedField: z.number().register(argMetadata, {
14571457
deprecationReplacement: 'replacedField',
14581458
}),
1459-
},
1459+
}),
14601460
});
14611461

14621462
expect(options).to.deep.equal({
@@ -1486,9 +1486,9 @@ describe('arg-parser', function () {
14861486
'--unknownField',
14871487
'100',
14881488
],
1489-
schema: {
1489+
schema: z.object({
14901490
extendedField: z.enum(['90', '100']),
1491-
},
1491+
}),
14921492
})
14931493
).to.throw(UnknownCliArgumentError, 'Unknown argument: --unknownField');
14941494
});

packages/arg-parser/src/arg-parser.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,14 @@ export function parseArgsWithCliOptions({
228228
}: {
229229
args: string[];
230230
/** Schema to extend the CLI options schema with. */
231-
schema?: Record<string, z.ZodTypeAny>;
231+
schema?: z.ZodObject;
232232
}): ReturnType<typeof parseArgs<CliOptions>> {
233233
const schema =
234234
schemaToExtend !== undefined
235-
? CliOptionsSchema.extend(schemaToExtend)
235+
? z.object({
236+
...CliOptionsSchema.shape,
237+
...schemaToExtend.shape,
238+
})
236239
: CliOptionsSchema;
237240
const { parsed, positional, deprecated } = parseArgs<ParsedCliOptions>({
238241
args,

0 commit comments

Comments
 (0)