2024-08-16 17:40:24 +02:00
|
|
|
import parsetoml
|
|
|
|
|
|
|
|
import ../model/config_type
|
2024-08-17 19:00:30 +02:00
|
|
|
import notifier_config
|
2024-08-16 17:40:24 +02:00
|
|
|
export config_type
|
|
|
|
|
2024-08-18 19:45:37 +02:00
|
|
|
proc parseSourceDirectories*(in_conf: TomlValueRef): seq[string] =
|
|
|
|
var src_dirs: seq[string] = @[]
|
|
|
|
for dir in in_conf{"source_directories"}.getElems():
|
|
|
|
src_dirs.add(dir.getStr())
|
|
|
|
# this is here for backwards compatibiliy
|
2024-08-16 17:40:24 +02:00
|
|
|
for dir in in_conf{"source_dirs"}.getElems():
|
2024-08-18 19:45:37 +02:00
|
|
|
norg_config.source_directories.add(dir.getStr())
|
|
|
|
return src_dirs
|
|
|
|
|
|
|
|
proc parseEncryption*(enc_conf: TomlValueRef) =
|
|
|
|
norg_config.setEncryptionPassphrase(enc_conf{"encryption_passphrase"}.getStr(""))
|
|
|
|
|
|
|
|
proc parseRepositories*(rep_conf: TomlValueRef): seq[Repository] =
|
|
|
|
var repos: seq[Repository] = @[]
|
|
|
|
for r in rep_conf.getElems():
|
2024-08-16 17:40:24 +02:00
|
|
|
let rtable = r.getTable()
|
|
|
|
var repo = Repository()
|
|
|
|
repo.path = rtable["path"].getStr()
|
|
|
|
repo.label = rtable["label"].getStr()
|
2024-08-18 19:45:37 +02:00
|
|
|
repos.add(repo)
|
|
|
|
return repos
|
|
|
|
|
|
|
|
proc parseConfigFile*(file: string): NorgConfig =
|
|
|
|
norg_config = newNorgConfig()
|
|
|
|
let in_conf = parsetoml.parseFile(file)
|
|
|
|
norg_config.source_directories = parseSourceDirectories(in_conf)
|
|
|
|
parseEncryption(in_conf{"encryption"})
|
|
|
|
norg_config.repositories = parseRepositories(in_conf{"repositories"})
|
2024-08-17 19:00:30 +02:00
|
|
|
norg_config.notifiers = parseNotifiers(in_conf)
|
2024-08-16 17:40:24 +02:00
|
|
|
return norg_config
|
|
|
|
|
|
|
|
|