mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Improve interaction between -x and -f eval flags
#241
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cakemanny on GitHub (Nov 2, 2024).
When using eval's
-xoption, the--formatoption appears to be ignored.Evaluating the following
gives
I had expected it to give
Checked with
Pkl 0.26.3 (macOS 14.4.1, native)and a build from main,Pkl 0.27.0-dev+9692504 (macOS 14.6.1, native).If only always wanting a fixed format, a workaround for now is to configure both wishes in the output property.
Details
@HT154 commented on GitHub (Nov 2, 2024):
This a dupe of #742
@cakemanny commented on GitHub (Nov 2, 2024):
Ahh, ok. So what I have to understand is that the default for
-xis actuallyoutput.textand that--formatchanges the renderer that is used to construct that value.I guess the part about
-xandoutput.textis implied in the online docs about pkl eval. Though not apparent when only reading the CLI--helpoutput.Perhaps it's possible to improve the docs for the
--formatoption, make it clearer that it's changing the modules' renderers rather than ensuring a specific output format.I think Pkl stands out here as, with Pkl, rendering happens inside the language behind this hidden output property. Anyone coming to Pkl from another configuration language might expect that the language stops once the contents of the module file have been computed and then the tool is rendering to the supported formats.
Rereading the introduction's concepts, the paragraph on evaluation seems to misrepresent Pkl in this regard:
To me it implies that Pkl works like how I understand Dhall, CUE and KCL to work. (Which I now believe not to be the case).
Sorry for this wall of text. I really just wanted to try to explore where my misconceptions came from and see if I could help find a way to avoid someone else falling into this trap.
Also, in case it's helpful, the use case that I had was: given a large amount of configuration in a single module, can Pkl select and output only part of it. That's what I was after when I spotted the
-xoption. In case that's useful input to future ergonomics.@odenix commented on GitHub (Nov 2, 2024):
Is there a reason why
-xisn't defined as "set output.value"?@HT154 commented on GitHub (Nov 2, 2024):
Modules can set
output.textdirectly sooutput.valuemay be ignored entirely.@odenix commented on GitHub (Nov 3, 2024):
Right, but I think this problem already exists for
-f.The following would at least be consistent and easy to explain:
-xoverridesoutput.valueand resetsoutput.text-foverridesoutput.rendererand resetsoutput.text@bioball commented on GitHub (Nov 3, 2024):
I think that sentence is a little misleading, but it's actually correct in the strict sense. The conversion can be: Pkl string -> string bytes (in the case of the CLI), or can also be: Pkl object to class/struct/primitive in a host language (in the case of using Pkl as a library).
To your point, the discrepancy between Pkl and Cue/KCL/Dhall is that rendering happens in-language, and you can affect how rendering happens when you author Pkl code.
One of the use-cases for the
-xflag is for scripting use-cases, for example,pkl eval -x 'package.version'.If it was defined as
set output.value, you'd get something like:Instead of:
But, I'm more and more thinking that we should provide some way to improve the interaction between
-xand-f. Or, introduce a new flag to address this pain point.@ThinkChaos commented on GitHub (Jan 17, 2025):
Posting here so it's more visible, but the workaround was given in #752:
-x 'module.output.renderer.renderValue(<expr>).FWIW I hit this while evaluating Pkl and it seems like unfortunate behavior to me.
If
module.output.renderis set correctly, why is it ignored? (I get that-xsets it too, it's rhetorical)I think changing it so
-xsetsmodule.rendererinstead would make it more intuitive.