15

We have a project with huge configuration files built using hocon configs. There is an intention to use variables where possible to create template_section and setup some values in template based on some options.

The problem is that while using variables in this config, I have to refer to absolute path all the time. Is it possible somehow to use canonical name (if properties located on same level)?

Example:

foo {
    bar = 4
    baz = ${foo.bar} // work perfect
    baz = ${[this].bar} // can I do smth like that? Any ideas.
}

More real-life example. What I'm actually looking for is general OOP abilities in building hocon configs. I have some parent configuration template_config with important_option inside that really depends on implementation: custom_config1 or custom_config2 , what I have to do currently is to implement important_option in both children configurations because with absolute pathes I have to refer to custom config sectsions names.

custom_config1: $template_config {
    child_option = child_value1
}

custom_config2: $template_config {
    child_option = child_value2
}

template_config {
    important_option = ${child_option} // NOT POSSIBLE
    child_option = not_implemented
}
vvg
  • 6,075
  • 14
  • 32
  • What you mean by 'reach config.'? Was that meant to be 'rich'? By reading the specs, it seems that what you want is not possible. paths are absolute, not relative. https://github.com/typesafehub/config/blob/master/HOCON.md#path-expressions – Johnny Everson Feb 15 '16 at 16:57
  • thx, I've checked spec as well and had not found any options. – vvg Feb 15 '16 at 17:02
  • 2
    I think your best bet here is to wrap this logic you want in the Scala configuration object. – Johnny Everson Feb 15 '16 at 17:40
  • Shouldn't you write the full path from the root, i.e. `template_config.child_option`. – axel22 Mar 21 '16 at 16:13
  • This is also a problem when the variable is inside an unnamed config, for example inside an array of configs. Then you can't refer to it by it's path e.g. `outer { list : [ { anonymous : config }, { another : config } ] }` – Luciano Dec 21 '16 at 11:57

0 Answers0