Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define switch for key=value

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.

like image 894
Arrrrrrr Avatar asked Mar 08 '26 15:03

Arrrrrrr


1 Answers

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
like image 109
def- Avatar answered Mar 11 '26 09:03

def-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!