1
0
Fork
You've already forked nim-gemconf
0
Gemconf configuration file parser
  • Nim 100%
2024年05月22日 05:21:50 +00:00
doc Initial commit 2024年05月22日 05:21:50 +00:00
tests Initial commit 2024年05月22日 05:21:50 +00:00
.gitignore Initial commit 2024年05月22日 05:21:50 +00:00
gemconf.nim Initial commit 2024年05月22日 05:21:50 +00:00
gemconf.nimble Initial commit 2024年05月22日 05:21:50 +00:00
readme.md Initial commit 2024年05月22日 05:21:50 +00:00

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")

License

0BSD