src/prologue/core/configure

Source   Edit  

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

Example:

import src/prologue/core/configure
import os, tables, streams


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


discard getAllPrologueEnv(prefix)


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

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

Types

ConfigFileExt = enum
  Json = "json", Toml = "toml", Yaml = "yaml"
Source   Edit  
Env = object
Source   Edit  
EnvError = object of CatchableError
Source   Edit  
EnvWrongFormatError = object of EnvError
Source   Edit  

Procs

func `$`(env: Env): string {.inline, ...raises: [], tags: [], forbids: [].}
Gets the string form of Env. Source   Edit  
func `[]`(env: Env; key: string): string {.inline, ...raises: [KeyError], tags: [],
    forbids: [].}
Source   Edit  
func contains(env: Env; key: string): bool {.inline, ...raises: [], tags: [],
    forbids: [].}
Returns true if key exists in Env. Source   Edit  
proc delPrologueEnv(key: string; prefix: string) {.inline, ...raises: [OSError],
    tags: [WriteEnvEffect], forbids: [].}
Source   Edit  
proc existsPrologueEnv(key: string; prefix: string): bool {.inline, ...raises: [],
    tags: [ReadEnvEffect], forbids: [].}
Source   Edit  
func get(env: Env; key: string): string {.inline, ...raises: [KeyError], tags: [],
    forbids: [].}
Retrieves a value of key in Env. Source   Edit  
proc getAllPrologueEnv(prefix: string): OrderedTableRef[string, string] {.
    inline, ...raises: [], tags: [ReadEnvEffect], forbids: [].}
Gets all (key, val) pairs with prefix from environment variables. Source   Edit  
func getOrDefault[T: BaseType](env: Env; key: string; default: T): T {.inline.}
Retrieves a value of key if key exists in Env. Otherwise the default value will be returned. Source   Edit  
proc getPrologueEnv(): string {....raises: [], tags: [ReadEnvEffect], forbids: [].}
Gets PROLOGUE env variables. Source   Edit  
proc getPrologueEnv(key: string; prefix: string; default = ""): string {.inline,
    ...raises: [], tags: [ReadEnvEffect], forbids: [].}
Gets (key, val) pairs with prefix from environment variables. If key can't be found, default will be returned. Source   Edit  
func hasKey(env: Env; key: string): bool {.inline, ...raises: [], tags: [],
    forbids: [].}
Returns true if key exists in Env. Source   Edit  
func initEnv(): Env {.inline, ...raises: [], tags: [], forbids: [].}
Initializes an Env. Source   Edit  
proc loadPrologueEnv(filename: string): Env {.
    ...raises: [IOError, OSError, Exception, ValueError, EnvWrongFormatError],
    tags: [ReadIOEffect, RootEffect, WriteIOEffect], forbids: [].}
Source   Edit  
proc putPrologueEnv(key, val: string; prefix: string) {.inline,
    ...raises: [OSError], tags: [WriteEnvEffect], forbids: [].}
Puts (key, val) pairs with prefix to environment variables. Source   Edit  
proc setPrologueEnv(env: Env; key, value: string) {.inline, ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc writePrologueEnv(filename: string; env: Env) {....raises: [IOError, OSError],
    tags: [WriteIOEffect], forbids: [].}
Source   Edit  

Iterators

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