docker-minecraft-server icon indicating copy to clipboard operation
docker-minecraft-server copied to clipboard

Allow shell expansion style defaults in variable replacements

Open ChipWolf opened this issue 3 years ago • 3 comments

Enhancement Type

Improve an existing feature

Describe the enhancement

Currently, the variable replacement mechanism has no option to define defaults inline; this means all parameters you add become required inputs and a breaking change to your configuration. I propose we allow default values to be defined in a similar style to bash parameter expansion §{CFG_USERNAME:-root}. Wether or not you want to be fully compliant with all of the various intricacies of bash parameter expansion is on the table, but default values are more than enough for my use case.

Perhaps the only other potentially useful mechanism is the ability to use a different variable as the default. This would be useful in situations like this where you have a global variable, but also want to expose granularity for specific use cases ${CFG_FORGE_LOGLEVEL:=CFG_LOGLEVEL}.

Thanks!

ChipWolf avatar Jun 14 '22 14:06 ChipWolf

On reflection, the bash parameter expansion style pattern replacements or inverse defaults could also be useful for situations like this:

<Root level="all">
  <filters>
    <MarkerFilter marker="NETWORK_PACKETS" onMatch="${${CFG_FORGE_LOGLEVEL:+ALLOW}:-DENY}" onMismatch="NEUTRAL"/>
  </filters>
  <AppenderRef ref="Console" level="${sys:forge.logging.console.level:-${CFG_FORGE_LOGLEVEL:-info}}"/>
</Root>

If CFG_FORGE_LOGLEVEL is unset, this file should resolve to this:

<Root level="all">
  <filters>
    <MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
  </filters>
  <AppenderRef ref="Console" level="${sys:forge.logging.console.level:-info}"/>
</Root>

If CFG_FORGE_LOGLEVEL is set to debug, the file should resolve to this:

<Root level="all">
  <filters>
    <MarkerFilter marker="NETWORK_PACKETS" onMatch="ALLOW" onMismatch="NEUTRAL"/>
  </filters>
  <AppenderRef ref="Console" level="${sys:forge.logging.console.level:-debug}"/>
</Root>

Realistically, this specific example could be tricky because the interpreter needs to be context-aware to acknowledge nested shell expansions to set onMatch but also must ignore the ${sys:forge.. parameter that must be stored in this particular conf file as-is.

In reality, I'd likely have two variables for this file so the interpreter only should modify parameters that match the defined REPLACE_ENV_VARIABLE_PREFIX.

ChipWolf avatar Jun 14 '22 15:06 ChipWolf

@itzg should this be moved to itzg/mc-server-runner?

ChipWolf avatar Nov 10 '22 12:11 ChipWolf

It would be mc-image-helper, but also need at a minimum the issue here to track the catalyst for the change.

itzg avatar Nov 10 '22 12:11 itzg