Show HN: gq – like jq or zq, but you use Go (github.com)
Hi HN. I've gotten pretty tired of needing to learn a custom programming language for a tool I use once a week or less. So I figured, it might be easier to pick up if `jq` used a programming language I already know. Voila, gq.
73 comments
[ 2.7 ms ] story [ 133 ms ] thread[0] https://github.com/itchyny/gojq
Edit: oh unlike jq/gojq your tool doesn't implement the jq language it allows you to script in Go. Cool! And interesting to see your use of the Yaegi interpreter for interpreting the Go.
I'm curious, did you find it faster to interpret with Yaegi vs just writing the Go code to a temp file and build/running that? I imagine at some point for larger datasets the latter approach would be faster?
You allow users to run arbitrary Go somewhere?
No guesses which language the `h` stands for :)
https://github.com/dflemstr/rq
It misses XML though, and activity in development ;)
Sorry to disappoint? :)
[0] https://github.com/aeshirey/jsx
I find it especially handy for poc-ing helm snippets, although regrettably they don't have the same "standard library" of functions
Learning the jq syntax will have a much better payoff in the long run.
every map implementation ive seen has type function(a,b) -> list(a) -> list(b)
select(contains("good/")) is a function from string -> string|void
so map plus a voidable function equals a filter
| just means connect 2 filters
if you have a stream you turn it into a array with the array constructor []
if you have an array you turn it into a stream with the producer operator .[]
the api is super orthogonal and well designed. but you do have to understand the model
We need competing implementations in more languages!
(Ignore my snarky tone because: why not?)
https://unix.stackexchange.com/questions/450614/is-there-a-w...
Python is my daily driver, but I still use JQ when I'm doing something quick. If you try some complex examples, I'd bet you'll quickly figure out why.
I never said every single library, also Python scripts can run as standalone executables.
If you truly can’t have Python because it’s too bloated, then JQ in shell scripts is a fair use case, that just sounds so rare.
Hear hear! Building bona-fide compilers that have interesting concepts, or just for fun, is a worthwhile thing to do. But these one-off languages are becoming ridiculous.
* buildah shows just how much of a headache Dockerfiles are. We already have a whole ecosystem of awesome scripting languages, such as bash, fish, zx, etc. Instead, we have to deal with the incredibly constrained (and harmfully magic) behavior of docker build.
* the whole implerative YAML ecosystem. I have been playing around with Dagger (CUE, a language built to solve real problems), and what a joy compared implerative CI.
* lest we forget how JavaScript came to be: https://thenewstack.io/brendan-eich-on-creating-javascript-i...
I don't understand this mentality. Some programmers enjoy writing programs and some enjoy learning about programming languages. No one is telling all programmers they they need to learn about every programming language, but why paint the whole endeavor as frivolous?
> Building bona-fide compilers that have interesting concepts, or just for fun, is a worthwhile thing to do.
> No one is telling all programmers they they need to learn about every programming language
I cringe a little.
There are about 25 different DSL's in my head from configuring various desired state configuration systems or services which use DSLs, there's countless config file formats ranging for ZONE files to TOML to YAML to HCL and on and on and on.
Makefiles, Dockerfiles, Ninja files, Jenkinsfiles etc;etc;etc;etc;
DevOps of Yore had to know bash and perl, then it was Ruby, then python, now Go. The treadmill continues, it's _necessary_ to learn those things because you _must_ interact with those things.
That's before we get into special languages like AWK which had significant prominence when I was beginning life as a sysadmin too.
Nobody is forcing programmers to know every language, but honestly, there's a lot that sysadmins had to learn, and with the rise of DevOps, developers are the SysAdmins of tomorrow: so you have to know what we knew.
But I don't understand why you'd say it'd make you cringe.
You can have a discussion about how the industry (usually motivated by non-technical reasons) is moving towards. I was talking specifically about those "one-off" languages that some people find fun to investigate and/or work on.
But in order to do a good job a sysadmin has to learn the semantics of dozens.
So you’re right, in a way, but it’s not right at all for sysadmins.
Since sysadmins are being essentially replaced by programmers, it won’t be right for programmers soon either.
Also +1 to dagger+cue. I like that it gives me essentially for full power in buildkit's llb exposed as cue configs.
The problem I was trying to solve was container signing, as well as building AMD64+ARM64 multi-arch images without buildx having access to both contexts, i.e. on different VMs (a CircleCI limitation). When you use buildah without bud you learn just how many implicit steps are involved in a Dockerfile, and how those implicit steps have been the problem all along.
buildx works great when you're on the razor thin happy path. The abstraction is great for the majority who need it but, crucially, Dockerfiles provide no way to escape the abstractions.
my.tar contains files owned by user 0, I want them to be owned by nobody:
Damn, --chown does not work when untaring and doesn't fail either but the files end up being owned by root. Fine, I'll just chmod Now it fails (of course) because the files are owned by root and the command is ran as nobody.While it all makes sense, I'm not sure why it's logic to have the ADD command always run as root and the others following the USER directive (yeah and I know, it's all my bad for using ADD rather then COPY)
Did you know: RUNning chmod increases the size of the layer by the size of the file being chmodded[1]. Just some more of that magical secret sauce.
(With buildah you choose when to create a layer, so both the COPY and the chmod can be layered together)
[1]: https://blog.vamc19.dev/posts/dockerfile-copy-chmod/
https://news.ycombinator.com/item?id=13091469
However, for deep `jq` selects I use `<file.json | gron | grep key -C n | norg` where `norg` is `gron --ungron`.
I also prefer `gron` for ad-hoc pipelines and `jq` for longer-lasting ones.
For instance json is a subset of yaml, maybe internally jq they could use yaml libraries, consume either, output either json or input format by default and give me a flag for yaml output if I want it.
As a guy who does a bunch of devops and works with a bunch of teams to improve their pipelines etc. jq is a tool they all have and i always find in pipelines having to install the new jq flavor of the month every six months is terrible.
As it happens, gojq, mentioned elsewhere in this thread, adds this feature, and quite a few others.
Jq has served the industry admirably, but there's always room for improvement.
Alternatively: the tool should use sql.
The amount of time I spent on getting all that working is probably a lot less than waiting a few extra seconds on a python script I run every few days so…
Maybe a nice middle ground would be for more language runtimes to have an equivalent to perl's `-p` flag. https://perldoc.perl.org/perlrun#-p
This flag is so convenient that I mostly use `perl -pe` instead of `sed` for regex search-and-replace.
[0] https://github.com/kellyjonbrazil/jello