Open ulken opened 1 year ago
Same thing happens with zod.number()
, so not isolated to zod.string()
.
@vadimdemedes I started looking into it. Even though I lack knowledge of Zod's internals, judging by generate-options.ts#L66C3-L89C52:
```ts const description = getDescription(optionSchema.description); let valueDescription = getValueDescription(optionSchema.description); let isOptional = isOptionalByDefault; // Unwrap zod.string().optional() if (optionSchema instanceof ZodOptional) { isOptional = true; optionSchema = optionSchema._def.innerType; } // Unwrap zod.string().optional().default() if (optionSchema instanceof ZodDefault) { isOptional = true; defaultValue = optionSchema._def.defaultValue(); optionSchema = optionSchema._def.innerType; } // Unwrap zod.string().default().optional() if (optionSchema instanceof ZodOptional) { isOptional = true; optionSchema = optionSchema._def.innerType; } const alias = getAlias(optionSchema.description); let flag = `--${name}`; ```
my best guess is by reassigning optionSchema
to _def.innerType
, we lose the special __parsel
prefix of description
, causing the config lookup to "fail".
getAlias()
is the only config lookup from there on, so I suppose it supports that theory?
Potential fixes:
getAlias()
before the reassignmentdescription
value and pass that to getAlias()
I might be missing something, though.
@vadimdemedes I'll gladly help out here if you could just give your thoughts on the matter.
I'm trying to define an alias for an option, but it's not working if used with neither
zod.default()
norzod.optional()
.Try it out: https://codesandbox.io/p/devbox/infallible-jones-ys358t?file=/string-default-alias/source/commands/index.tsx:6,1
Run
npm run build
(maybe followed bynpm link
) and thenda -h
.Works 👍
Outputs:
Doesn't work 👎
and
Outputs:
(default only in the first case, obviously)