@@ -157,7 +157,7 @@ Boolean = [
157157```
158158crates/
159159 plotnik-cli/ # CLI tool
160- src/commands/ # Subcommands (debug, docs, langs)
160+ src/commands/ # Subcommands (debug, docs, exec, langs, types )
161161 plotnik-core/ # Common code
162162 plotnik-lib/ # Plotnik as library
163163 src/
@@ -177,20 +177,68 @@ Run: `cargo run -p plotnik-cli -- <command>`
177177
178178- ` debug ` — Inspect queries and source file ASTs
179179 - Example: ` cargo run -p plotnik-cli -- debug -q '(foo) @bar' `
180+ - ` exec ` — Execute query against source, output JSON
181+ - Example: ` cargo run -p plotnik-cli -- exec -q '(identifier) @id' -s app.js `
182+ - ` types ` — Generate TypeScript type definitions from query
183+ - Example: ` cargo run -p plotnik-cli -- types -q '(identifier) @id' -l javascript `
180184- ` langs ` — List supported languages
181185
182186Inputs: ` -q/--query <Q> ` , ` --query-file <F> ` , ` --source <S> ` , ` -s/--source-file <F> ` , ` -l/--lang <L> `
183187
184- Output (inferred from input): ` --only-symbols ` , ` --cst ` , ` --raw ` , ` --spans ` , ` --cardinalities `
188+ ### ` debug ` output flags
189+
190+ - ` --only-symbols ` — Show only symbol table (requires query)
191+ - ` --cst ` — Show query CST instead of AST
192+ - ` --raw ` — Include trivia tokens (whitespace, comments)
193+ - ` --spans ` — Show source spans
194+ - ` --cardinalities ` — Show inferred cardinalities
195+ - ` --graph ` — Show compiled transition graph
196+ - ` --graph-raw ` — Show unoptimized graph (before epsilon elimination)
197+ - ` --types ` — Show inferred types
185198
186199``` sh
187200cargo run -p plotnik-cli -- debug -q ' (identifier) @id'
188201cargo run -p plotnik-cli -- debug -q ' (identifier) @id' --only-symbols
202+ cargo run -p plotnik-cli -- debug -q ' (identifier) @id' --graph -l javascript
203+ cargo run -p plotnik-cli -- debug -q ' (identifier) @id' --types -l javascript
189204cargo run -p plotnik-cli -- debug -s app.ts
190205cargo run -p plotnik-cli -- debug -s app.ts --raw
191206cargo run -p plotnik-cli -- debug -q ' (function_declaration) @fn' -s app.ts -l typescript
192207```
193208
209+ ### ` exec ` output flags
210+
211+ - ` --pretty ` — Pretty-print JSON output
212+ - ` --verbose-nodes ` — Include line/column positions in nodes
213+ - ` --check ` — Validate output against inferred types
214+ - ` --entry <NAME> ` — Entry point name (definition to match from)
215+
216+ ``` sh
217+ cargo run -p plotnik-cli -- exec -q ' (program (expression_statement (identifier) @name))' --source ' x' -l javascript
218+ cargo run -p plotnik-cli -- exec -q ' (identifier) @id' -s app.js --pretty
219+ cargo run -p plotnik-cli -- exec -q ' (function_declaration) @fn' -s app.ts -l typescript --verbose-nodes
220+ cargo run -p plotnik-cli -- exec -q ' (identifier) @id' -s app.js --check
221+ cargo run -p plotnik-cli -- exec -q ' (identifier) @id' -s app.js --verbose-nodes --pretty
222+ cargo run -p plotnik-cli -- exec -q ' A = (identifier) @id B = (string) @str' -s app.js --entry B
223+ ```
224+
225+ ### ` types ` output flags
226+
227+ - ` --format <FORMAT> ` — Output format: ` typescript ` or ` ts ` (default: typescript)
228+ - ` --root-type <NAME> ` — Name for root type of anonymous expressions (default: Query)
229+ - ` --verbose-nodes ` — Use verbose Node shape (matches ` exec --verbose-nodes ` )
230+ - ` --no-node-type ` — Don't emit Node/Point type definitions
231+ - ` --no-export ` — Don't add ` export ` keyword to types
232+ - ` -o/--output <FILE> ` — Write output to file instead of stdout
233+
234+ ``` sh
235+ cargo run -p plotnik-cli -- types -q ' (identifier) @id' -l javascript
236+ cargo run -p plotnik-cli -- types -q ' Func = (function_declaration name: (identifier) @name body: (statement_block) @body)' -l js
237+ cargo run -p plotnik-cli -- types -q ' (identifier) @id' -l javascript --verbose-nodes
238+ cargo run -p plotnik-cli -- types -q ' (identifier) @id' -l javascript --no-node-type
239+ cargo run -p plotnik-cli -- types -q ' (identifier) @id' -l javascript -o types.d.ts
240+ ```
241+
194242# Coding rules
195243
196244- Avoid nesting logic: prefer early exit in functions (return) and loops (continue/break)
0 commit comments