fix: jp2a requires --key=value arg format
jp2a 1.3.x does not accept space-separated long option args. Added _argFormat: 'equals' to jp2a schema so buildArgs emits --key=value for value flags. Also mirrors chafa's width/height → --size=WxH combining in runJp2a. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a95c184be7
commit
9a4e501be9
@ -97,12 +97,12 @@ describe('buildArgs', () => {
|
|||||||
|
|
||||||
it('accepts jp2a RGB weight values', () => {
|
it('accepts jp2a RGB weight values', () => {
|
||||||
expect(buildArgs('jp2a', { red: '0.5', green: '0.3', blue: '0.2' })).toEqual([
|
expect(buildArgs('jp2a', { red: '0.5', green: '0.3', blue: '0.2' })).toEqual([
|
||||||
'--red', '0.5', '--green', '0.3', '--blue', '0.2',
|
'--red=0.5', '--green=0.3', '--blue=0.2',
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('accepts jp2a edge-threshold', () => {
|
it('accepts jp2a edge-threshold', () => {
|
||||||
expect(buildArgs('jp2a', { 'edge-threshold': '0.4' })).toEqual(['--edge-threshold', '0.4'])
|
expect(buildArgs('jp2a', { 'edge-threshold': '0.4' })).toEqual(['--edge-threshold=0.4'])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('accepts valid img2txt format values', () => {
|
it('accepts valid img2txt format values', () => {
|
||||||
|
|||||||
@ -22,6 +22,8 @@ export const SCHEMAS = {
|
|||||||
format: { type: 'value', valid: ['symbols', 'utf8'] },
|
format: { type: 'value', valid: ['symbols', 'utf8'] },
|
||||||
},
|
},
|
||||||
jp2a: {
|
jp2a: {
|
||||||
|
_argFormat: 'equals',
|
||||||
|
size: { type: 'value' },
|
||||||
width: { type: 'value' },
|
width: { type: 'value' },
|
||||||
height: { type: 'value' },
|
height: { type: 'value' },
|
||||||
chars: { type: 'value' },
|
chars: { type: 'value' },
|
||||||
@ -60,6 +62,7 @@ export function buildArgs(tool, flags) {
|
|||||||
const schema = SCHEMAS[tool]
|
const schema = SCHEMAS[tool]
|
||||||
if (!schema) throw new Error(`Unknown tool: ${tool}`)
|
if (!schema) throw new Error(`Unknown tool: ${tool}`)
|
||||||
|
|
||||||
|
const equals = schema._argFormat === 'equals'
|
||||||
const args = []
|
const args = []
|
||||||
for (const [key, value] of Object.entries(flags)) {
|
for (const [key, value] of Object.entries(flags)) {
|
||||||
const def = schema[key]
|
const def = schema[key]
|
||||||
@ -69,6 +72,8 @@ export function buildArgs(tool, flags) {
|
|||||||
}
|
}
|
||||||
if (def.type === 'bool') {
|
if (def.type === 'bool') {
|
||||||
if (value) args.push(`--${key}`)
|
if (value) args.push(`--${key}`)
|
||||||
|
} else if (equals) {
|
||||||
|
args.push(`--${key}=${String(value)}`)
|
||||||
} else {
|
} else {
|
||||||
args.push(`--${key}`, String(value))
|
args.push(`--${key}`, String(value))
|
||||||
}
|
}
|
||||||
@ -87,7 +92,12 @@ export async function runChafa(imagePath, flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runJp2a(imagePath, flags) {
|
export async function runJp2a(imagePath, flags) {
|
||||||
const args = buildArgs('jp2a', flags)
|
const { width, height, ...rest } = flags
|
||||||
|
const processed = { ...rest }
|
||||||
|
if (width && height) processed.size = `${width}x${height}`
|
||||||
|
else if (width) processed.size = `${width}x`
|
||||||
|
else if (height) processed.size = `x${height}`
|
||||||
|
const args = buildArgs('jp2a', processed)
|
||||||
return execa('jp2a', [...args, imagePath], { timeout: TIMEOUT })
|
return execa('jp2a', [...args, imagePath], { timeout: TIMEOUT })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user