Replies: 2 comments 1 reply
-
It's not the looping that's erroring, but your gomplate doesn't allow reassigning map values (because it's not supported by Go's templating language), so this won't work. Instead of reassigning the value you could simply use it within that loop:
here's a working sample: $ gomplate -d 'alacritty=https://raw.githubusercontent.com/lighthaus-theme/alacritty/master/src/lighthaus.yml?type=application/yaml' \
-i '{{ range $key, $value := (ds "alacritty").colors.normal -}}
do something with {{ strings.ReplaceAll "#" "" $value | strings.ToLower }}
{{ end }}'
do something with 18191e
do something with 1d918b
do something with 00bfa4
do something with 44b273
do something with d16bb7
do something with fc2929
do something with cccccc
do something with e25600 An alternative, since that particular file is otherwise in lowercase anyway (except for comments), would be to $ gomplate -d 'alacritty=https://raw.githubusercontent.com/lighthaus-theme/alacritty/master/src/lighthaus.yml?type=application/yaml' \
-i '{{ $map := include "alacritty" | strings.ToLower | data.YAML -}}
{{ range $key, $value := $map.colors.normal -}}
do something with {{ strings.ReplaceAll "#" "" $value }}
{{ end }}'
do something with 18191e
do something with 1d918b
do something with 00bfa4
do something with 44b273
do something with d16bb7
do something with fc2929
do something with cccccc
do something with e25600 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the assist. That's not quite what I was after. I'm trying to transform in that loop so I can use the values in the clear later in my template rather than right then and there without having to assign each map value to its own variable. Even transforming and then assigning them to a second scrubbed map would be fine, but I don't see how I can declare new maps. Right now, I'm pre-processing with yq because I need these values transformed before I can use them, which might be the simplest way to get what I'm after. |
Beta Was this translation helpful? Give feedback.
-
I'm using an Alacritty YAML file as a datasource. It has a bunch of color values in it that I would like to transform before I can use them. Basically, I want to bulk change the '#00BFA4' style colors to '00bfa4' without having to do each and every one individually (ie: avoid running
| strings.ReplaceAll "#" "" | strings.ToLower
25+ times).I can get somewhat close to the results I'm hoping for, but turned my
map
into a string:If I try to loop through the map, I get
bad character U+005B '['"
.Clearly I'm a bit lost as to how to proceed.
Beta Was this translation helpful? Give feedback.
All reactions