In nim, you can define a symbol via -d:value
and test if it was defined with defined(value)
. It is possible however to define a key and retrieve its value? I'm looking for something in the vein of --colors:on
but user defined.
Asked
Active
Viewed 114 times
1 Answers
5
I also looked for this and didn't find anything for my nim-small-coreutils. I ended up using environment variables as a hack and read them in a nonportable manner:
const colors = staticExec "echo \"$colors\""
when colors == "on":
echo "It's on!"
else:
echo "I guess it's off? The value is: ", colors
This takes the environment variable at compile time, so you can use it like this:
colors=on nim c example
or alternatively:
nim c --putEnv:colors=on c example

def-
- 5,275
- 20
- 18
-
Hmmm, interesting hack. – Arrrrrrr Dec 06 '15 at 21:00