Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Machine-readable output (for search mode) #171

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexpovel
Copy link
Owner

So far, output for search mode was oriented around human readability. It wasn't easily
machine-readable, aka parsing it is difficult.

This change detects whether stdout is a terminal and switches to a more parse-friendly output if
not.

While an improvement, the implementation is junk
(PoC), and makes me think just providing JSON
output is preferable. Then, consumers have maximum flexibility and do not have to write weird custom
shell pipelines. A jq command would do.

For JSON support, we could provide a flag --json (ripgrep has that too), and MAYBE perform
auto-detection of TTY. For JSON support, we need a new type which encapsulates a new line found in
search mode. For example, could be struct
containing filename, findings, ranges,
line_number etc., and then is serialized to a
JSON line w/ serde.

So far, output for search mode was oriented around
human readability. It wasn't easily
machine-readable, aka parsing it is difficult.

This change detects whether `stdout` is a terminal
and switches to a more parse-friendly output if
not.

While an improvement, the implementation is junk
(PoC), and makes me think just providing JSON
output is preferable. Then, consumers have maximum
flexibility and do not have to write weird custom
shell pipelines. A `jq` command would do.

For JSON support, we could provide a flag `--json`
(ripgrep has that too), and MAYBE perform
auto-detection of TTY. For JSON support, we need a
new type which encapsulates a new line found in
search mode. For example, could be `struct`
containing `filename`, `findings`, `ranges`,
`line_number` etc., and then is serialized to a
JSON line w/ serde.
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