-
Notifications
You must be signed in to change notification settings - Fork 338
-
Pkl 0.28.2 (macOS 14.7.2, native) (installed with homebrew)
I've defined a bash script
#!/bin/bash # Check if the correct number of arguments are provided if [ "$#" -ne 2 ]; then echo "Usage: 0ドル <service_name> <component>" exit 1 fi # Set environment variables export SERVICE_NAME=1ドル export COMPONENT=2ドル # Run the pkl command pkl eval -f json -e SERVICE_NAME -e COMPONENT ./pkl-templates/my-template.pkl
and in the pkl file
COMPONENT = read("env:COMPONENT") SERVICE_NAME = read("env:SERVICE_NAME") ... Tags = new Dynamic { component = List( "${COMPONENT}" ) } ...
but it is not rendering it correctly here's what I get:
{
...
"Tags": {
"component": [
"${COMPONENT}"
]
}
}
Any help? The docs were not very clear that I could find about how to fit the cli and the pkl files together.
Beta Was this translation helpful? Give feedback.
All reactions
Your syntax for variable interpolation is incorrect:
-"${COMPONENT}" +"\(COMPONENT)"
You actually don't even need interpolation here, because COMPONENT is already a string. So it can just be component = List(COMPONENT).
In case you aren't already, I highly recommend using one of our editor plugins for writing Pkl, because it they will provide feedback about this to you.
Some other notes:
-
Listis a data type that's meant for in-language operations (map/flatmap/filter/etc). If you want to describe data, you should useListing. -
If your module only makes sense as JSON, you should go ahead and set the
output.renderer. Then, you don't need to add-f jsonanymore as a CLI flag.output { re...
Replies: 2 comments 2 replies
-
Your syntax for variable interpolation is incorrect:
-"${COMPONENT}" +"\(COMPONENT)"
You actually don't even need interpolation here, because COMPONENT is already a string. So it can just be component = List(COMPONENT).
In case you aren't already, I highly recommend using one of our editor plugins for writing Pkl, because it they will provide feedback about this to you.
Some other notes:
-
Listis a data type that's meant for in-language operations (map/flatmap/filter/etc). If you want to describe data, you should useListing. -
If your module only makes sense as JSON, you should go ahead and set the
output.renderer. Then, you don't need to add-f jsonanymore as a CLI flag.output { renderer = new JsonRenderer {} }
-
I think it makes more sense to model your inputs as external properties instead of env vars.
pkl eval -p SERVICE_NAME="1ドル" -p COMPONENT="2ドル" pkl-templates/my-template.pkl
With this, you'd
read("prop:SERVICE_NAME") -
Instead of using
Dynamic, try defining classes for your schema. Dynamic is sort of an escape hatch and has its uses, but generally you wouldn't use it for describing data. Also, try separating your data and schema into different files// MySchema.pkl Tags: Tags class Tags { component: Listing<String> } output { renderer = new JsonRenderer {} }
// myData.pkl amends "MySchema.pkl" tags { component { read("prop:COMPONENT") } }
Beta Was this translation helpful? Give feedback.
All reactions
-
@bioball I've updated my files based on your feedback and everything is working now, thanks for the prompt help.
Beta Was this translation helpful? Give feedback.
All reactions
-
@bioball I do have to interpolate it into a string somewhere else I omitted :
PolicyName = "my-github-org-${SERVICE_NAME}-deploy"
So I assume that is not how I should interpolate it.
Updated: I found the doc say \(<expr>) . This is what I get for trusting AI generated content.
Beta Was this translation helpful? Give feedback.
All reactions
-
Ah, yeah, as far as I can tell, none of the LLMs are good at Pkl
Beta Was this translation helpful? Give feedback.