Gemconf configuration file parser
| doc | Initial commit | |
| tests | Initial commit | |
| .gitignore | Initial commit | |
| gemconf.nim | Initial commit | |
| gemconf.nimble | Initial commit | |
| readme.md | Initial commit | |
Gemconf
This module is a basic Gemconf parser. Gemconf is a configuration format based on Gemtext from the Gemini protocol.
Features:
- A main section and two subsection levels
- Five value types: boolean, float, int, string, unnested sequences of the other four types
- Multiline string values
- Newline comments
Usage
Read a Gemconf
import gemconf
let conf = parseFile("config.gmi")
Use keys and values
import gemconf
let str = """
# gemconf
This is a comment. Below are key-value pairs.
* app: newapp
* downloads: 100
* rating: 5.0
* enabled: true
* keywords: nim, cli, utility
"""
var conf = parse(str)
assert getStr(conf, "gemconf/app") == "newapp"
assert getInt(conf, "gemconf/downloads") == 100
assert getFloat(conf, "gemconf/rating") == 5.0
assert getBool(conf, "gemconf/enabled") == true
assert getSeq(conf, "gemconf/keywords")[0].str == "nim"
# If the section is not specified, the key will be added
# to the top level.
add(conf, "updated", true)
assert getBool(conf, "gemconf/updated") == true
del(conf, "enabled")
assert contains(keys(conf), "gemconf/enabled") == false
Write to file
import gemconf
let str = """
# config
* host: example.tld
* port: 1965
"""
discard writeGemconf(parse(str), "config.gmi")