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

Add custom printing formatting #27

Closed
quasilyte opened this issue Aug 16, 2019 · 5 comments
Closed

Add custom printing formatting #27

quasilyte opened this issue Aug 16, 2019 · 5 comments

Comments

@quasilyte
Copy link
Owner

Define -format argument that accepts a string that describes how match results should be printed. If it's an empty string, the entire match is printed as is (current behavior).
For non-empty patterns every match is formatted accordingly.

Example:

phpgrep -format '$s' srcdir 'die("s:str")'

pattern: 'die("s:str")'
format: '$s'

input: die("hello")
output without format: die("hello")
output with format: "hello"
@quasilyte
Copy link
Owner Author

Should think beforehand how it interacts with #25.

@JTBrinkmann
Copy link

Would be great if we could use named matchers in the output (e.g. phpgrep -format '{{.x}}' test.php '$foo = ${x}')

@quasilyte
Copy link
Owner Author

@JTBrinkmann it's doable.
I'll figure something out in the near time.

@quasilyte
Copy link
Owner Author

Let's open a separate issue for this and close this one. I forgot to close this issue when -format was implemented.

@quasilyte
Copy link
Owner Author

Feel free to test it. :)
I added a few examples to the README.
The syntax is exactly identical to what you proposed.

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

No branches or pull requests

2 participants