Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Allow setting globals in config to set options
Browse files Browse the repository at this point in the history
Switch to a common config format using assignments to globals. E.g.

    return {statsfile = "foo"}

becomes

    statsfile = "foo"

Old format (returning a table) is still supported but has lower priority
on conflicts.
  • Loading branch information
mpeterv committed Jun 29, 2016
1 parent 505b9db commit d8a64d6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/luacov/runner.lua
Expand Up @@ -307,29 +307,30 @@ local function set_config(configuration)
runner.tick = runner.tick or runner.configuration.tick
end

local function die(error_msg)
io.stderr:write(("Error: %s\n"):format(error_msg))
raw_os_exit(1)
end

local function load_config_file(name, is_default)
local ok, conf, error_msg = util.load_config(name, _G)
local conf = setmetatable({}, {__index = _G})

local ok, ret, error_msg = util.load_config(name, conf)

if ok then
if type(conf) ~= "table" then
die("config is not a table")
if type(ret) == "table" then
for key, value in pairs(ret) do
if conf[key] == nil then
conf[key] = value
end
end
end

return conf
end

local error_type = conf
local error_type = ret

if error_type == "read" and is_default then
return nil
end

die(("couldn't %s config file %s: %s"):format(error_type, name, error_msg))
io.stderr:write(("Error: couldn't %s config file %s: %s\n"):format(error_type, name, error_msg))
end

local default_config_file = ".luacov"
Expand Down

0 comments on commit d8a64d6

Please sign in to comment.