|
| 1 | +#!/usr/bin/env node |
| 2 | +import { Command } from 'commander' |
| 3 | +import query from '../lib/command/query.js' |
| 4 | + |
| 5 | +const program = new Command() |
| 6 | + |
| 7 | +program |
| 8 | + .name('codeceptq') |
| 9 | + .description('Query HTML with CodeceptJS locators (CSS, XPath, fuzzy text, semantic).\n\nReads HTML from stdin or --file and prints matching elements with line numbers.') |
| 10 | + .argument('<locator>', 'locator string (CSS, XPath, or text for semantic match)') |
| 11 | + .argument('[context]', 'scope locator — restrict matches to descendants of context') |
| 12 | + .option('--field', 'treat locator as form field (input/textarea/select)') |
| 13 | + .option('--click', 'treat locator as clickable element (link, button, role=button, ...)') |
| 14 | + .option('--clickable', 'alias for --click') |
| 15 | + .option('--checkable', 'treat locator as checkbox/radio') |
| 16 | + .option('--select', 'treat locator as <option> visible text') |
| 17 | + .option('--xpath', 'force XPath interpretation') |
| 18 | + .option('--css', 'force CSS interpretation') |
| 19 | + .option('--file <path>', 'read HTML from file instead of stdin') |
| 20 | + .option('--limit <n>', 'cap matches printed', '20') |
| 21 | + .option('--snippet <chars>', 'truncate outerHTML per match to N characters', '500') |
| 22 | + .option('--full', 'print full outerHTML (no truncation)') |
| 23 | + .option('--json', 'output JSON') |
| 24 | + .addHelpText( |
| 25 | + 'after', |
| 26 | + ` |
| 27 | +Examples: |
| 28 | + cat trace/0001_page.html | codeceptq './/input' |
| 29 | + cat trace/0001_page.html | codeceptq 'Username' --field |
| 30 | + cat trace/0001_page.html | codeceptq 'Username' '.form' --field |
| 31 | + codeceptq './/button' --file trace/0001_page.html |
| 32 | + codeceptq 'Login' --click --file page.html |
| 33 | +
|
| 34 | +Exit codes: |
| 35 | + 0 matches found |
| 36 | + 1 no matches |
| 37 | + 2 invalid input or XPath |
| 38 | +`, |
| 39 | + ) |
| 40 | + .action(async (locator, context, options) => { |
| 41 | + try { |
| 42 | + await query(locator, context, options) |
| 43 | + } catch (err) { |
| 44 | + console.error(`codeceptq: ${err.message}`) |
| 45 | + process.exitCode = 2 |
| 46 | + } |
| 47 | + }) |
| 48 | + |
| 49 | +program.parseAsync(process.argv) |
0 commit comments