go-debos / debos

Debian OS builder
Apache License 2.0
533 stars 136 forks source link

golang-template: parse bools from template expansion #203

Open obbardc opened 4 years ago

obbardc commented 4 years ago

Currently variables imported through -t option are parsed as strings, it would be great to parse as bools if true or false.

Consider the difference between the two recipes:

working:

{{- $label := or .label "true" -}}

architecture: arm64
actions:
{{ if eq $label "true" }}
  - action: run
    command: echo TRUE
{{ end }}

{{ if eq $label "false" }}
  - action: run
    command: echo FALSE
{{ end }}

  - action: run
    chroot: false
    command: echo "END"

it makes it potentially simpler to read using bools:

{{- $label := or .label true -}}

architecture: arm64
actions:
{{ if $label }}
  - action: run
    command: echo TRUE
{{ end }}

{{ if not $label }}
  - action: run
    command: echo FALSE
{{ end }}

  - action: run
    chroot: false
    command: echo "END"
vigneshraman commented 3 years ago

Tried using map[string]interface{} instead of map[string]string for TemplateVars to have different types for key. But the parser (github.com/jessevdk/go-flags.Parser) is not parsing the value correctly

TemplateVars: map[string]interface {} [
        "label": nil, 
    ],