summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2021-02-04 13:59:55 +0100
committerGitHub <noreply@github.com>2021-02-04 13:59:55 +0100
commitcccf219cebfafbf1913dfdfdce70d285127bc440 (patch)
treea23a622e783734bdef4f5169fccd29f66ae9330a
parent14c61ecf24110f3f6a1a4a9c88439e568065ddd9 (diff)
downloadNim-cccf219cebfafbf1913dfdfdce70d285127bc440.tar.gz
Allow strings for -- in config.nims (#16934)
-rw-r--r--lib/system/nimscript.nim23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/system/nimscript.nim b/lib/system/nimscript.nim
index 88bd4a6c8..d2f4e9c92 100644
--- a/lib/system/nimscript.nim
+++ b/lib/system/nimscript.nim
@@ -159,16 +159,29 @@ proc toDll*(filename: string): string =
 
 proc strip(s: string): string =
   var i = 0
-  while s[i] in {' ', '\c', '\L'}: inc i
+  while s[i] in {' ', '\c', '\n'}: inc i
   result = s.substr(i)
+  if result[0] == '"' and result[^1] == '"':
+    result = result[1..^2]
 
 template `--`*(key, val: untyped) =
-  ## A shortcut for ``switch(astToStr(key), astToStr(val))``.
-  switch(astToStr(key), strip astToStr(val))
+  ## A shortcut for `switch <#switch,string,string>`_
+  ## Example:
+  ##
+  ## .. code-block:: nim
+  ##
+  ##   --path:somePath # same as switch("path", "somePath")
+  ##   --path:"someOtherPath" # same as switch("path", "someOtherPath")
+  switch(strip(astToStr(key)), strip(astToStr(val)))
 
 template `--`*(key: untyped) =
-  ## A shortcut for ``switch(astToStr(key)``.
-  switch(astToStr(key), "")
+  ## A shortcut for `switch <#switch,string>`_
+  ## Example:
+  ##
+  ## .. code-block:: nim
+  ##
+  ##   --listCmd # same as switch("listCmd")
+  switch(strip(astToStr(key)))
 
 type
   ScriptMode* {.pure.} = enum ## Controls the behaviour of the script.