mirror of
https://github.com/status-im/nim-confutils.git
synced 2025-02-05 00:35:23 +00:00
Clean up the obsolete config loading code; Fix the tests
This commit is contained in:
parent
0fc26c5b25
commit
0a88d30e00
10
README.md
10
README.md
@ -429,16 +429,6 @@ The names of the environment variables are prefixed by the name of the
|
||||
program by default. They are matched in case-insensitive fashion and
|
||||
certain characters such as `-` and `_` are ignored.
|
||||
|
||||
#### `appName`
|
||||
|
||||
By default, this is obtained by calling Nim's `os.getAppFilename`.
|
||||
The specified value is used to determine the default config file location.
|
||||
|
||||
#### `vendorName`
|
||||
|
||||
This is equal to `appName` unless overridden.
|
||||
The specified value is used to determine the default config file location.
|
||||
|
||||
#### `configFileEnumerator`
|
||||
|
||||
A function responsible for returning a sequence of `ConfigFilePath` objects.
|
||||
|
@ -845,12 +845,6 @@ proc loadImpl[C, SecondarySources](
|
||||
# This is an initial naive implementation that will be improved
|
||||
# over time.
|
||||
|
||||
# users can override default `appendConfigFileFormats`
|
||||
# `appName`, and `vendorName`
|
||||
mixin appendConfigFileFormats
|
||||
mixin appName, vendorName
|
||||
appendConfigFileFormats(Configuration)
|
||||
|
||||
let (rootCmd, fieldSetters) = configurationRtti(Configuration)
|
||||
var fieldCounters: array[fieldSetters.len, int]
|
||||
|
||||
|
@ -15,9 +15,6 @@ Overview of this module:
|
||||
from `defaultValue` pragma.
|
||||
]#
|
||||
|
||||
const
|
||||
configFileRegs = CacheSeq"confutils"
|
||||
|
||||
type
|
||||
ConfFileSection = ref object
|
||||
children: seq[ConfFileSection]
|
||||
@ -271,7 +268,6 @@ proc generateConfigFileSetters(confType, optType: NimNode,
|
||||
let
|
||||
CF = ident "SecondarySources"
|
||||
T = confType.getType[1]
|
||||
arrayLen = configFileRegs.len
|
||||
optT = optType[0][0]
|
||||
SetterProcType = genSym(nskType, "SetterProcType")
|
||||
(setterProcs, assignments, numSetters) = generateSetters(T, CF, fieldsPaths)
|
||||
@ -306,44 +302,3 @@ macro generateSecondarySources*(ConfType: type): untyped =
|
||||
|
||||
let settersPaths = model.generateSettersPaths
|
||||
result.add generateConfigFileSetters(ConfType, result[^1], settersPaths)
|
||||
|
||||
macro appendConfigFileFormat*(ConfigFileFormat: type, configExt: string, configPath: untyped): untyped =
|
||||
configFileRegs.add newPar(ConfigFileFormat, configExt, configPath)
|
||||
|
||||
func appName*(_: type): string =
|
||||
# this proc is overrideable
|
||||
when false:
|
||||
splitFile(os.getAppFilename()).name
|
||||
"confutils"
|
||||
|
||||
func vendorName*(_: type): string =
|
||||
# this proc is overrideable
|
||||
"confutils"
|
||||
|
||||
func appendConfigFileFormats*(_: type) =
|
||||
# this proc is overrideable
|
||||
when false:
|
||||
# this is a typical example of
|
||||
# config file format registration
|
||||
appendConfigFileFormat(Envvar, ""):
|
||||
"prefix"
|
||||
|
||||
when defined(windows):
|
||||
appendConfigFileFormat(Winreg, ""):
|
||||
"HKCU" / "SOFTWARE"
|
||||
|
||||
appendConfigFileFormat(Winreg, ""):
|
||||
"HKLM" / "SOFTWARE"
|
||||
|
||||
appendConfigFileFormat(Toml, "toml"):
|
||||
os.getHomeDir() & ".config"
|
||||
|
||||
appendConfigFileFormat(Toml, "toml"):
|
||||
splitFile(os.getAppFilename()).dir
|
||||
|
||||
elif defined(posix):
|
||||
appendConfigFileFormat(Toml, "toml"):
|
||||
os.getHomeDir() & ".config"
|
||||
|
||||
appendConfigFileFormat(Toml, "toml"):
|
||||
"/etc"
|
||||
|
@ -119,25 +119,6 @@ const
|
||||
confPathCurrUser = "tests" / "config_files" / "current_user"
|
||||
confPathSystemWide = "tests" / "config_files" / "system_wide"
|
||||
|
||||
# appName, vendorName, and appendConfigFileFormats
|
||||
# are overrideables proc related to config-file
|
||||
func appName(_: type TestConf): string =
|
||||
"testApp"
|
||||
|
||||
func vendorName(_: type TestConf): string =
|
||||
"testVendor"
|
||||
|
||||
func appendConfigFileFormats(_: type TestConf) =
|
||||
appendConfigFileFormat(Envvar, ""):
|
||||
"prefix"
|
||||
|
||||
when defined(windows):
|
||||
appendConfigFileFormat(Winreg, ""):
|
||||
"HKCU" / "SOFTWARE"
|
||||
|
||||
appendConfigFileFormat(Winreg, ""):
|
||||
"HKLM" / "SOFTWARE"
|
||||
|
||||
# User might also need to extend the serializer capability
|
||||
# for each of the registered formats.
|
||||
# This is especially true for distinct types and some special types
|
||||
@ -191,11 +172,13 @@ proc testConfigFile() =
|
||||
|
||||
test "basic config file":
|
||||
let conf = TestConf.load(secondarySources = proc (config: TestConf, sources: auto) =
|
||||
sources.addConfigFile(Envvar, InputFile "prefix")
|
||||
|
||||
if config.configFile.isSome:
|
||||
sources.addConfigFile(Toml, config.configFile.get)
|
||||
else:
|
||||
sources.addConfigFile(Toml, InputFile(confPathCurrUser & ".toml"))
|
||||
sources.addConfigFile(Toml, InputFile(confPathSystemWide & ".toml"))
|
||||
sources.addConfigFile(Toml, InputFile(confPathCurrUser / "testVendor" / "testApp.toml"))
|
||||
sources.addConfigFile(Toml, InputFile(confPathSystemWide / "testVendor" / "testApp.toml"))
|
||||
)
|
||||
|
||||
# dataDir is in env var
|
||||
|
Loading…
x
Reference in New Issue
Block a user