Skip to content

feat: add elastic esql command group#254

Draft
Anaethelion wants to merge 10 commits into
mainfrom
feat/esql-command-group
Draft

feat: add elastic esql command group#254
Anaethelion wants to merge 10 commits into
mainfrom
feat/esql-command-group

Conversation

@Anaethelion
Copy link
Copy Markdown

@Anaethelion Anaethelion commented Apr 29, 2026

Summary

  • Adds a new top-level elastic esql command group with sub-commands: query, watch, tail, check, save, and queries
  • Launches an interactive REPL when elastic esql is invoked on a TTY with no sub-command
  • Lazy-loads the module at CLI startup so other commands are unaffected

Ported from https://github.com/elastic/esqlcli.

Commits

The work is split into 9 atomic commits: transport test seam → ES|QL client → formatter → inject/saved-queries → hints → sub-commands → REPL → CLI wiring → tests.

Test plan

  • npm test passes (build + unit + license)
  • elastic esql query 'FROM <index> | LIMIT 5' returns results
  • elastic esql on a TTY launches the REPL
  • elastic esql --help lists all sub-commands
  • Pipe input: echo "FROM logs | LIMIT 1" | elastic esql query -

Exposes an internal setter so unit tests can inject a custom Transport
instance (e.g. with maxRetries: 0) without going through the full
initialisation path.
Thin wrapper around the shared Transport that executes ES|QL queries
and surfaces structured EsqlError on API failures.
Renders ES|QL response columns/values as table, json, ndjson, csv, or
tsv. Includes stats printing and partial-result warnings.
inject.ts rewrites an ES|QL query to append or merge a WHERE predicate.
saved-queries.ts handles named query persistence and {{placeholder}}
param substitution.
Provides completion/suggestion hints for ES|QL keywords and functions,
used by the REPL.
- query: execute one or more ES|QL queries with format, time-filter,
  param substitution, and output-file options
- watch: re-run a query on an interval, clearing the screen each cycle
- tail: stream new rows matching a query as they arrive
- check: validate query syntax without executing
- save / queries: persist and list named queries
Launches when `elastic esql` is invoked on a TTY with no sub-command.
Supports history, hints, and multi-line input.
registerEsqlCommands() assembles the `esql` command group. cli.ts
lazy-loads it only when the first argument is `esql`, keeping startup
fast for all other commands.
Covers client, formatter, inject, saved-queries, hints, REPL, and each
sub-command (query, tail, check) including time-flag parsing and stats.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 8.88s
✅ REPOSITORY gitleaks yes no no 83.49s
✅ REPOSITORY git_diff yes no no 0.3s
✅ REPOSITORY secretlint yes no no 11.5s
✅ REPOSITORY trivy yes no no 18.01s
✅ TYPESCRIPT eslint 25 0 0 4.48s

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

watch.ts: remove unused handleError import that triggered
@typescript-eslint/no-unused-expressions via a bare-expression hack.

client.test.ts: replace real HTTP server + UndiciConnection approach
with mock transports. UndiciConnection crashes under Bun
(response.headers undefined at UndiciConnection.js:159). Auth header
tests are rewritten to inspect the connection pool directly, which
avoids any actual network I/O and works on both Node and Bun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant