apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
10.16k stars 271 forks source link

Not possible to use `output` keyword even surrounded by backticks #670

Closed dshatokhin closed 1 hour ago

dshatokhin commented 2 hours ago

I'm generating a json output for the object with key name output but even if I enclose it in backticks pkl throws an error:

`output` {
  key = "value"
}
> pkl eval keywords.pkl -f json
–– Pkl Error ––
Cannot find property `key` in object of type `ModuleOutput`.

2 | key = "value"
    ^^^
at keywords#output (file:///home/denis/github/envoy-gateway-vm/private/keywords.pkl, line 2)

Available properties:
files
renderer
text
value

I'm expecting it to work as any other keywords such as class, module, string etc:

> pkl eval keywords.pkl -f json
{
  "class": {
    "key": "value"
  }
}

> pkl eval keywords.pkl -f json
{
  "module": {
    "key": "value"
  }
}

> pkl eval keywords.pkl -f json
{
  "string": {
    "key": "value"
  }
}

Version used Pkl 0.26.3 on amd64 Linux machine

bioball commented 2 hours ago

The output property is a special property on Module, and can only be used to describe the module's output.

To get around this, you'll need to define a class with output as a property, then set your module's output to a value of that class.

class Foo {
  output: Output
}

class Output {
  key: String
}

foo: Foo = new {
  output {
    key = "foo"
  }
}

output {
  value = foo
}

This produces:

output {
  key = "foo"
}
dshatokhin commented 1 hour ago

@bioball , thanks for such a quick reply, I will then use the workaround you suggested