prologue/core/configure

This module contains basic configure facilities like retrieving, setting environment variables and so on.

Example:

import os, tables, streams


let prefix = "PROLOGUE_"
# only work in application scope
putPrologueEnv("debug", "true", prefix)
putPrologueEnv("port", "8080", prefix)
putPrologueEnv("appName", "Starlight", prefix)
putPrologueEnv("staticDir", "static", prefix)


let res = getAllPrologueEnv(prefix)

doAssert(res.len == 4, "got: " & $res)

let config = newStringStream("""[Prologue]
debug=true
port=8080
appName=Starlight
staticDir=static
""")

let tab = loadConfig(config)["Prologue"]
doAssert tab["appName"] == "Starlight"
doAssert tab["staticDir"] == "static"
doAssert tab["debug"] == "true"
doAssert tab["port"] == "8080"

Types

Env = object
  data: OrderedTableRef[string, string]
  Source Edit
EnvError = object of CatchableError
  Source Edit
EnvWrongFormatError = object of EnvError
  Source Edit

Procs

proc initEnv(): Env {...}{.raises: [], tags: [].}
  Source Edit
proc `$`(env: Env): string {...}{.raises: [], tags: [].}
  Source Edit
proc `[]`(env: Env; key: string): string {...}{.raises: [KeyError], tags: [].}
  Source Edit
proc hasKey(env: Env; key: string): bool {...}{.raises: [], tags: [].}
  Source Edit
proc contains(env: Env; key: string): bool {...}{.raises: [], tags: [].}
  Source Edit
proc get(env: Env; key: string): string {...}{.inline, raises: [KeyError], tags: [].}
  Source Edit
proc getOrDefault[T: BaseType](env: Env; key: sink string; default: T): T {...}{.inline.}
  Source Edit
proc putPrologueEnv(key, val: string; prefix: string) {...}{.inline, raises: [OSError],
    tags: [WriteEnvEffect].}
  Source Edit
proc getPrologueEnv(key: string; prefix: string; default = ""): string {...}{.inline,
    raises: [], tags: [ReadEnvEffect].}
  Source Edit
proc getAllPrologueEnv(prefix: string): OrderedTableRef[string, string] {...}{.inline,
    raises: [], tags: [ReadEnvEffect].}
  Source Edit
proc existsPrologueEnv(key: string; prefix: string): bool {...}{.inline, raises: [],
    tags: [ReadEnvEffect].}
  Source Edit
proc delPrologueEnv(key: string; prefix: string) {...}{.inline, raises: [OSError],
    tags: [WriteEnvEffect].}
  Source Edit
proc loadPrologueEnv(filename: string): Env {...}{.
    raises: [IOError, OSError, Exception, ValueError, EnvWrongFormatError],
    tags: [ReadIOEffect, RootEffect, WriteIOEffect].}
  Source Edit
proc setPrologueEnv(env: Env; key, value: string) {...}{.raises: [], tags: [].}
  Source Edit
proc writePrologueEnv(filename: string; env: Env) {...}{.
    raises: [IOError, OSError, Exception], tags: [WriteIOEffect].}
  Source Edit

Iterators

iterator keys(env: Env): string {...}{.raises: [], tags: [].}
  Source Edit
iterator values(env: Env): string {...}{.raises: [], tags: [].}
  Source Edit
iterator pairs(env: Env): (string, string) {...}{.raises: [], tags: [].}
  Source Edit