openpencil/packages/cli/src/commands/query.ts
Danila Poyarkov 7f91594d0c refactor: standardize acronym casing
- Rename first-party API, RPC, JSON, CORS, SVG, JSX, and related identifiers to preserve acronym casing
- Keep upstream and serialized boundary names unchanged
- Add a lint guardrail and migration notes for exported APIs
2026-08-10 15:48:16 +03:00

57 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineCommand } from 'citty'
import type { QueryNodeResult } from '@open-pencil/core/rpc'
import { appTargetOptions } from '#cli/app-target'
import { printNodeResults, printError } from '#cli/format'
import { loadRPCData } from '#cli/rpc-data'
export default defineCommand({
meta: {
description: 'Query nodes using XPath selectors'
},
args: {
file: {
type: 'positional',
description: 'Document file path (omit to connect to running app)',
required: false
},
selector: {
type: 'positional',
description: 'XPath selector (e.g., //FRAME[@width < 300], //TEXT[contains(@name, "Label")])',
required: true
},
page: { type: 'string', description: 'Page name (default: all pages)' },
limit: { type: 'string', description: 'Max results (default: 1000)', default: '1000' },
...appTargetOptions,
json: { type: 'boolean', description: 'Output as JSON' }
},
async run({ args }) {
const results = await loadRPCData<QueryNodeResult[] | { error: string }>(
args.file,
'query',
{
selector: args.selector,
page: args.page,
limit: args.limit ? Number(args.limit) : undefined
},
args
)
if ('error' in results) {
printError(results.error)
process.exit(1)
}
if (args.json) {
console.log(JSON.stringify(results, null, 2))
return
}
printNodeResults(results, (n) => {
const q = n as { width?: number; height?: number; name: string }
return `${q.name} ${q.width}×${q.height}`
})
}
})