Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ export function defineCommand<T extends z.ZodType> (config: CommandConfig<T>): O
const { simplifyZodIssues, formatIssuesText } = await import('./lib/zod-error.js')
const issues = simplifyZodIssues(result.error.issues)
if (jsonFormat === true) {
process.stderr.write(JSON.stringify({
const writeErr = cmd.configureOutput().writeErr ?? ((s: string) => process.stderr.write(s))
writeErr(JSON.stringify({
error: {
code: 'input_validation_failed',
message: `Input validation failed with ${issues.length} issue(s)`,
Expand Down
7 changes: 0 additions & 7 deletions test/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1705,19 +1705,12 @@ describe('defineCommand', () => {
prog.exitOverride()
cmd.exitOverride()
let out = ''
const origOut = process.stdout.write.bind(process.stdout)
const origErr = process.stderr.write.bind(process.stderr)
process.stdout.write = (chunk: unknown) => { out += String(chunk); return true }
process.stderr.write = (chunk: unknown) => { out += String(chunk); return true }
prog.configureOutput({ writeOut: (s) => { out += s }, writeErr: (s) => { out += s } })
cmd.configureOutput({ writeOut: (s) => { out += s }, writeErr: (s) => { out += s } })
try {
await prog.parseAsync(['--json', cmd.name(), ...argv], { from: 'user' })
} catch {
// exitOverride throws on cmd.error(); that's expected
} finally {
process.stdout.write = origOut
process.stderr.write = origErr
}
let parsed: unknown = null
try { parsed = JSON.parse(out) } catch { /* not JSON - test will fail on assertion */ }
Expand Down
Loading