Skip to content

refactor: command/query separation — extract CLI wrappers, shared output helper#373

Merged
carlos-alm merged 6 commits intomainfrom
refactor/command-query-separation
Mar 9, 2026
Merged

refactor: command/query separation — extract CLI wrappers, shared output helper#373
carlos-alm merged 6 commits intomainfrom
refactor/command-query-separation

Conversation

@carlos-alm
Copy link
Copy Markdown
Contributor

Summary

  • Extract 15 CLI display wrappers (~800 lines) from queries.jsqueries-cli.js, reducing queries.js by 26% (3433 → 2544 lines)
  • Add outputResult() helper in result-formatter.js — replaces the 4–6 line JSON/NDJSON dispatch pattern repeated in every CLI wrapper
  • Extract isTestFile() into test-filter.js — breaks the circular-ish dependency where 17 modules imported it from queries.js
  • Add QUERY_OPTS CLI preset — consolidates 7 repeated .option() calls across 14 commands (~98 lines removed)

Details

New files

File Purpose
src/result-formatter.js outputResult(data, field, opts) — returns true if JSON/NDJSON handled
src/test-filter.js isTestFile() + TEST_PATTERN — standalone, no deps on queries.js
src/queries-cli.js 15 CLI wrappers: symbolPath, stats, queryName, impactAnalysis, moduleMap, fileDeps, fnDeps, context, children, explain, where, roles, fileExports, fnImpact, diffImpact

What stays unchanged

  • All *Data() functions remain in queries.js — MCP, batch, and programmatic API untouched
  • All public exports preserved via index.js re-exports — zero breaking changes
  • No function renames, no signature changes

Bug fix

  • cfg.js was calling printNdjson(data.results) (passing array directly) instead of printNdjson(data, 'results') — fixed via outputResult

Test plan

  • 569 unit + integration tests pass (0 failures)
  • biome check — 0 errors (1 pre-existing warning)
  • codegraph --help — all commands listed correctly
  • codegraph impact --help — shows QUERY_OPTS options

🤖 Generated with Claude Code

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant