Skip to content

Commit ad1ecf9

Browse files
authored
Merge pull request #106 from oxince/master
2 parents 05a19e5 + 7e41283 commit ad1ecf9

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/cli.lua

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ package.path = script_path() .. "?.lua;" .. package.path;
1313
local Prometheus = require("prometheus");
1414
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Info;
1515

16-
-- Override error callback
17-
--[[Prometheus.Logger.errorCallback = function(...)
18-
print(Prometheus.colors(Prometheus.Config.NameUpper .. ": " .. ..., "red"))
19-
os.exit(1);
20-
end]]
21-
2216
-- Check if the file exists
2317
local function file_exists(file)
2418
local f = io.open(file, "rb")
2519
if f then f:close() end
2620
return f ~= nil
2721
end
2822

23+
string.split = function(str, sep)
24+
local fields = {}
25+
local pattern = string.format("([^%s]+)", sep)
26+
str:gsub(pattern, function(c) fields[#fields+1] = c end)
27+
return fields
28+
end
29+
2930
-- get all lines from a file, returns an empty
3031
-- list/table if the file does not exist
3132
local function lines_from(file)
@@ -90,6 +91,21 @@ while i <= #arg do
9091
luaVersion = "LuaU";
9192
elseif curr == "--pretty" then
9293
prettyPrint = true;
94+
elseif curr == "--saveerrors" then
95+
-- Override error callback
96+
Prometheus.Logger.errorCallback = function(...)
97+
print(Prometheus.colors(Prometheus.Config.NameUpper .. ": " .. ..., "red"))
98+
99+
local args = {...};
100+
local message = table.concat(args, " ");
101+
102+
local fileName = sourceFile:sub(-4) == ".lua" and sourceFile:sub(0, -5) .. ".error.txt" or sourceFile .. ".error.txt";
103+
local handle = io.open(fileName, "w");
104+
handle:write(message);
105+
handle:close();
106+
107+
os.exit(1);
108+
end;
93109
else
94110
Prometheus.Logger:warn(string.format("The option \"%s\" is not valid and therefore ignored", curr));
95111
end

src/logger.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function logger:warn(...)
4949
end
5050
end
5151

52-
logger.errorCallback = function(...)
52+
logger.errorCallback = function(...)
5353
print(colors(config.NameUpper .. ": " .. ..., "red"))
5454
error(...);
5555
end;

0 commit comments

Comments
 (0)