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

what is meaning of def in this template? #540

Open
zffocussss opened this issue Nov 27, 2024 · 4 comments
Open

what is meaning of def in this template? #540

zffocussss opened this issue Nov 27, 2024 · 4 comments

Comments

@zffocussss
Copy link

is it a keyword,or just a custom literal?

def is_alpine:

@dagood
Copy link
Contributor

dagood commented Nov 27, 2024

That file is a jq template, so that's https://jqlang.github.io/jq/manual/#defining-functions.

There are complications behind the scenes if you dig into https://github.com/docker-library/golang/blob/master/apply-templates.sh, but I've been able to work on a fork of this repo fine after realizing it was jq syntax.

(If anyone has docs that point out what these files really are in detail, I would like to know. I was never able to find anything.)

@tianon
Copy link
Member

tianon commented Nov 27, 2024

Documenting it better is on our (very long) TODO list, but https://github.com/docker-library/bashbrew/blob/f71d6ef63e1f5abe6d5cb06a62a3e5e42d68566e/scripts/jq-template.awk is the file that actually does the work. 😅

@dagood
Copy link
Contributor

dagood commented Nov 27, 2024

Aha, I was under the impression that the {{ and - logic was a mysterious part of jq (or part of awk), and the similarity to Go text/template meant I never needed to dig deeper to see where that comes from. Never noticed it's directly implemented by that file. 😄 Thanks. (I have that file checked into my fork to avoid the network dependency, so I had a chance to spot it!)

@tianon
Copy link
Member

tianon commented Nov 27, 2024

It's certainly extremely text/template inspired, so you weren't too far off! 😄

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

3 participants