danburzo / hred

Reduce HTML and XML to JSON from the command line, using an expressive query language inspired by CSS selectors.
https://danburzo.ro/projects/hred/
MIT License
67 stars 1 forks source link

Flag to read query from file. #6

Closed tejing1 closed 2 years ago

tejing1 commented 2 years ago

I've found myself writing hred "$(<filename)" somewhat frequently, as queries are often just a little too large to ergonomically inline in a script.

Most major text stream processing tools with their own domain specific language, like jq, sed, and awk, can be invoked as prog -f filename instead of prog 'dsl code', so it would make sense for hred to have the same functionality.

danburzo commented 2 years ago

I think that's a great idea, @tejing1. -f seems to be a common choice for the short option, and I'm thinking either --from or --file as the long counterpart.

tejing1 commented 2 years ago

awk --file sed --file jq --from-file

--file is probably the least surprising long option name.

Not sure what other tools to compare against off the top of my head.

danburzo commented 2 years ago

Yeah, ripgrep uses --file as well. I didn't like it at first because I felt --from is a bit more explicit, but I will change it for consistency.

danburzo commented 2 years ago

The -f / --file option is available in hred@1.5.0. Thanks for the suggestion!

tejing1 commented 2 years ago

You're welcome, and thanks for the super quick response. Not to mention for making my personal favorite tool in this category. :smile: