add config file validation #2

Merged
luna merged 7 commits from config-validation into mistress 2022-12-07 18:50:30 +00:00
3 changed files with 13 additions and 8 deletions
Showing only changes of commit 8354478e72 - Show all commits

View file

@ -114,10 +114,11 @@ local function loadConfigFile()
local config_file_function = assert(loadstring(config_file_data))
local config_object = config_file_function()
local schema_errors = validateConfigFile(config_object)
if schema_errors then
for name, errors in pairs(schema_errors) do
log('CONFIG ERROR' .. writeSchemaErrors(errors, log))
end
local total_count = table.pprint(schema_errors, {call=function() end})
if total_count > 0 then
log('CONFIG ERROR')
table.pprint(schema_errors, {call=log})
end
return config_object
end

View file

@ -8,6 +8,7 @@
local ctx = require('ctx')
local config = require('config')
require('util')
ctx:loadFromConfig(config.loadConfigFile())

View file

@ -4,21 +4,24 @@ function table.len(t)
return count
end
function table.pprint(t, ident, total_count)
function table.pprint(t, options, ident, total_count)
local ident = ident or 0
local total_count = total_count or 0
local options = options or {}
local print_function = options.call or print
if type(t) == 'table' then
local count = 0
for k, v in pairs(t) do
print(string.rep('\t', ident) .. k)
print_function(string.rep('\t', ident) .. k)
count = count + 1
total_count = pprint(v, ident + 1, total_count)
total_count = table.pprint(v, options, ident + 1, total_count)
end
if count == 0 then
--print('<empty table>')
end
else
print(string.rep('\t', ident) .. tostring(t))
print_function(string.rep('\t', ident) .. tostring(t))
total_count = total_count + 1
end
return total_count