carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.66k stars 135 forks source link

[lang] support multiline arguments to annotations #149

Open cppforlife opened 4 years ago

cppforlife commented 4 years ago

Describe the problem/challenge you have I want to be able to annotate a node using an expression formatted over multiple lines, but ytt currently only accepts a single line per annotation.

Describe the solution you'd like For example,

#@schema/desc """
#@ something something
#@ """
a: 123

#@overlay/match by=overlay.subset({
#@  "kind": "Foo",
#@  "metadata": {"blah": "blah"},
#@ })
b: 123

Anything else you would like to add:


Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible" 👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

pivotaljohn commented 2 years ago

Requested: https://kubernetes.slack.com/archives/CH8KCCKA5/p1650629876052489

cmoulliard commented 2 years ago

We should also to have the possibility to pass the function to the next line Now

--- #@ generate_certificate(name,namespace,cert_duration,cert_renew_before,cert_secret_name,common_name,dns_names,cert_subject, cert_keystore, issuer_name)

Expected

--- 
#@ generate_certificate(name,namespace,cert_duration,cert_renew_before,cert_secret_name,common_name,dns_names,cert_subject, cert_keystore, issuer_name)

and pass the args on multilines Now

--- #@ generate_certificate(name,namespace,cert_duration,cert_renew_before,cert_secret_name,common_name,dns_names)

Expected

--- 
#@ generate_certificate(name,namespace, 
                        cert_duration,
                        cert_renew_before,
                        cert_secret_name,
                        common_name,
                        dns_names)
pivotaljohn commented 2 years ago

We should also to have the possibility to pass the function to the next line

I see how the format you're looking for is more intuitive. 👍🏻

However, it's one thing to recognize an annotation is spilling over onto subsequent lines. It's a whole 'nother thing to start to attach annotations to a node that is above the annotation.

Little known fact: the #@ is a short-hand for two annotations. When #@ appears to the right of a node, it's (internally) identified as a #@template/value annotation. When there is no node to the left of the annotation it's a #@template/code.

So, we'd start introducing corner-cases into this crucial "algorithm" that identifies to which node an annotation is attached and what kind of @template/... annotation is implied.

Not saying it's not possible; noting the internal complexity that would result (which increases the risk of bugs).