@@ -13,19 +13,20 @@ package.path = script_path() .. "?.lua;" .. package.path;
1313local Prometheus = require (" prometheus" );
1414Prometheus .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
2317local function file_exists (file )
2418 local f = io.open (file , " rb" )
2519 if f then f :close () end
2620 return f ~= nil
2721end
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
3132local 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
0 commit comments