emrichen icon indicating copy to clipboard operation
emrichen copied to clipboard

Typecasting?

Open lukeschlather opened this issue 4 years ago • 1 comments

I ran into an issue where I was trying to make a kubernetes manifest for a volumeMount and I wanted to make it configurable whether or not the volume was readOnly. I'm just using --include-env which means that when I provide the environment variable false it gets turned into the string 'false'.

I ended up doing

!Defaults
read_only_bool: !Op [!Var read_only, eq, 'true']

But it seems like it would be nice to have like a

read_only_bool: !Coerce [Boolean, !Var read_only]

That could apply standard yaml type guessing to the string and throw an error if it wasn't right (e.g. if you provided read_only=5 that would be a number and so would throw an error, or if you Coerced to numeric then you would end up with an error if you provided the string 'false'.)

lukeschlather avatar Jul 08 '21 20:07 lukeschlather

Thank you for your suggestion.

We're likely to implement this as a !ToX family of tags (eg. !ToString 3.14, !ToInt value: "C0FFEE", radix: 16 etc.) as we already have !IsString etc.

japsu avatar Jul 11 '21 16:07 japsu