mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
getEnv now supports a 'default' parameter; refs #6019
This commit is contained in:
@@ -94,7 +94,7 @@ proc findEnvVar(key: string): int =
|
||||
if startsWith(environment[i], temp): return i
|
||||
return -1
|
||||
|
||||
proc getEnv*(key: string): TaintedString {.tags: [ReadEnvEffect].} =
|
||||
proc getEnv*(key: string, default = ""): TaintedString {.tags: [ReadEnvEffect].} =
|
||||
## Returns the value of the `environment variable`:idx: named `key`.
|
||||
##
|
||||
## If the variable does not exist, "" is returned. To distinguish
|
||||
@@ -108,7 +108,7 @@ proc getEnv*(key: string): TaintedString {.tags: [ReadEnvEffect].} =
|
||||
return TaintedString(substr(environment[i], find(environment[i], '=')+1))
|
||||
else:
|
||||
var env = c_getenv(key)
|
||||
if env == nil: return TaintedString("")
|
||||
if env == nil: return TaintedString(default)
|
||||
result = TaintedString($env)
|
||||
|
||||
proc existsEnv*(key: string): bool {.tags: [ReadEnvEffect].} =
|
||||
|
||||
@@ -106,7 +106,7 @@ proc cmpic*(a, b: string): int =
|
||||
## Compares `a` and `b` ignoring case.
|
||||
cmpIgnoreCase(a, b)
|
||||
|
||||
proc getEnv*(key: string): string {.tags: [ReadIOEffect].} =
|
||||
proc getEnv*(key: string; default = ""): string {.tags: [ReadIOEffect].} =
|
||||
## Retrieves the environment variable of name `key`.
|
||||
builtin
|
||||
|
||||
|
||||
Reference in New Issue
Block a user