From 92de44270bb46a13fd1b6e183a904083f18dbc2a Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 21 May 2017 09:32:26 -0700 Subject: [PATCH] Initial notes --- Using-nimscript-for-configuration.md | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Using-nimscript-for-configuration.md diff --git a/Using-nimscript-for-configuration.md b/Using-nimscript-for-configuration.md new file mode 100644 index 0000000..1f19da9 --- /dev/null +++ b/Using-nimscript-for-configuration.md @@ -0,0 +1,40 @@ +The [nimscript docs](* https://nim-lang.org/docs/nimscript.html) describe the nimscript API, but I needed some help on how to use it. (Most of the following applies to nimble too, but let's concentrate on nimscript for now.) + +### Example +Suppose you have a scrDir like this: +``` +src/ + foo.nim + foo.nim.cfg + foo.nims + nim.cfg + zzz.nims +``` + +Suppose `foo.nims` looks like this: +```nim +echo "In foo.nims" + +include "zzz.nims" + +task mybuild, "My build task": + echo "In mybuild" + switch("verbosity", "2") + setCommand "c" + +task newtask, "My new task": + echo "In newtask" + setCommand "dump" +``` +And `zzz.nims` looks like this: +```nim +echo "In zzz.nims" +``` +You *could* run your nimscript like this: `nim e foo.nims`, but that will not make your tasks available. + +Instead, run **nim** on `foo.nim` like this: + + nim newtask foo + nim mybuild -d:debug foo + +All the [standard `.cfg` files](https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files) are read *before* your nimscript. You can use `include` to avoid repeating code for each tool-specific `.nims` file. That's not quite as convenient as a global `nim.cfg` file, but it's more flexible. \ No newline at end of file