I'm failing the configurable hello-world test with this particular instance:
cron.template:
!YS-v0:
apiVersion: batch/v1
kind: CronJob
metadata:
name:: $(ENV.CRON_NAME)
spec:
schedule: "*/7 * * * *"
...
And when I run:
$ CRON_NAME=blip ys -Y cron.template
Compile error: Odd number of elements in map
What am I missing/getting wrong?Also would it be possible to include line numbers (and columns) in error messages?
I worked it out. Actually I should say Chris O worked it out -- the $(ENV.CRON_NAME) part needs to be double-quoted. And some error messages do include line numbers
afternoon
simply:
name:: ENV.CRON_NAME
would be fine"... $(...) ..." is interpolation syntax
I'll try that.
exactly
but you aren't interpolating an expression into a string
Took a little more wrangling to make one line in an array interpolatable and landed on
- ! "..."
well don't interpolate just to get a variable or expression value
just use the var or expr
if you need it inside a string then interpolate using double quoted or literal style scalars in code mode
The final line is the last part of a complex ["bash", "-c", "CMD ; CMD ; ... CMD"]
Anyway I have it working
you can dm it to me if you want a review
but glad it works 🙂
Sorry to bother you, how is this supposed to work. With input:
!YS-v0:
let:
name:: ENV.CRON_NAME
match: (re-matches #".*bb(\d+)t(\d+)" name)
do:
spec:
name:: name
# match:: match
how do I formulate a match?
$ CRON_NAME=ct13bb29t4 ys -Y cron.template3
let:
name: ct13bb29t4
match: (re-matches
do:
spec:
name: !!clojure.core$name {}
I figured I could deconstruct the name to pull out a version and a minutes value but am running into issues. Not much in the docs. Gemini, our official recommended AI tool, came up with plenty of erroneous suggestions. Anyway have to go now. This is a very interesting tool inlining lisp into yaml - I just need to read the docs more thoroughly and pick up the subtletiesI'm at a restaurant but I can answer in about 30 minutes
@eric.promislow this should give you insight: https://gist.github.com/ingydotnet/8598725ed647f4aa3339a2103b7406c8 There's lots of ways to write things. Feel free to ask questions. And also point out places that need better doc.
it should be obvious but the 3rd command there ys -U -c ... (you can use -Uc as well) is the YAML compiled to Clojure.
BTW, -U is to compile mappings to {"a" 1, "b" 2} (normal mapping with unordered keys) rather than the default (% "a" 1, "b" 2) (ordered mapping).
I just thought the output would be easier to read.
This is a very interesting tool inlining lisp into yaml@eric.promislow I realized that I think you have a misunderstanding of what YS is...
It's not inlining lisp into yaml. The entire yaml file is a lisp program.
IOW, YS is a complete Lisp with a YAML syntax.
Every YAML data file is a valid YS "program".
A program that evaluates to the data value that it expresses.
Take any YAML (or JSON, since JSON is YAML) file and run ys -c any.yaml and it will output Lisp (Clojure) code.
Sure, given a regular YAML, that lisp code is just lisp syntax for a data mapping or vector literal.
When you run ys -Y file.yaml the file is read, compiled to clojure/lisp, evaluated by a clojure runtime to a single value, and then the value is printed (as YAML since you chose -Y).
Hope that makes it clearer. 🙂
@chris032 ^^