Summary
When defining command options with kebab-case keys in a Zod schema (e.g., 'dry-run'), --help correctly displays --dry-run but ctx.args['dry-run'] is always undefined at runtime. Only the camelCase variant ctx.args.dryRun works. Both forms should be valid accessors since the schema key is the user's source of truth.
Current behavior
const options = z.object({
'dry-run': z.boolean().default(false).describe('Preview without writing'),
})
export default command({
options,
handler: (ctx) => {
ctx.args['dry-run'] // undefined — always falls through to default
ctx.args.dryRun // works — but doesn't match the schema key
},
})
--help shows --dry-run correctly, but the value is never accessible via the schema key.
Root cause
cleanParsedArgs in packages/core/src/runtime/args/parser.ts:79-83 strips all keys containing -:
function cleanParsedArgs(argv: Record<string, unknown>): Record<string, unknown> {
return Object.fromEntries(
Object.entries(argv).filter(([key]) => key !== '_' && key !== '$0' && !key.includes('-'))
)
}
Yargs provides both dry-run and dryRun on argv. This filter removes dry-run, keeping only the camelCase dryRun. When the Zod schema expects dry-run, validation falls back to the .default() value since the key is missing.
Expected behavior
ctx.args['dry-run'] and ctx.args.dryRun should both return the parsed value. Either:
- Keep both — Don't strip kebab keys from cleaned args, or
- Normalize schema keys — Map kebab Zod keys to their camelCase equivalents before validation, then provide both on
ctx.args
Location
packages/core/src/runtime/args/parser.ts — cleanParsedArgs (~line 79)
Summary
When defining command options with kebab-case keys in a Zod schema (e.g.,
'dry-run'),--helpcorrectly displays--dry-runbutctx.args['dry-run']is alwaysundefinedat runtime. Only the camelCase variantctx.args.dryRunworks. Both forms should be valid accessors since the schema key is the user's source of truth.Current behavior
--helpshows--dry-runcorrectly, but the value is never accessible via the schema key.Root cause
cleanParsedArgsinpackages/core/src/runtime/args/parser.ts:79-83strips all keys containing-:Yargs provides both
dry-runanddryRunonargv. This filter removesdry-run, keeping only the camelCasedryRun. When the Zod schema expectsdry-run, validation falls back to the.default()value since the key is missing.Expected behavior
ctx.args['dry-run']andctx.args.dryRunshould both return the parsed value. Either:ctx.argsLocation
packages/core/src/runtime/args/parser.ts—cleanParsedArgs(~line 79)