Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env lua
- local languages = {
- ["C#"] = true
- }
- local lines_per_bowl = 100
- local function split(str, delimeters)
- local elements = {}
- string.gsub(str, "([^,]+)", function(value)
- table.insert(elements, value)
- end)
- return elements
- end
- local function read(dataFile)
- local fh = io.open(dataFile, "r")
- if not fh then return nil end
- local value = tonumber(fh:read("*a"))
- fh:close()
- return value
- end
- local function write(dataFile, data)
- local fh = io.open(dataFile, "w")
- fh:write(data)
- fh:close()
- end
- local function cloc(directory)
- local fh = io.popen("cloc --csv " .. directory)
- if not fh then error(directory) end
- local count = 0
- local line
- for i = 1, 6 do
- line = fh:read("*line")
- end
- while line do
- local parts = split(line, ",")
- if languages[parts[2]] then
- count = count + tonumber(parts[5])
- end
- line = fh:read("*line")
- end
- fh:close()
- return count
- end
- local function main(args)
- if #args ~= 2 then
- print("Usage: lfb <directory> <data-file>")
- return
- end
- local directory = args[1]
- local dataFile = args[2]
- local last = read(dataFile)
- local current = cloc(directory)
- if last then
- local difference = last - current
- print(difference .. " lines written/removed since last bowl.")
- if difference >= lines_per_bowl then
- print("Time for another bowl!")
- write(dataFile, current)
- else
- print("Keep coding! Only " .. (lines_per_bowl - difference) .. " more lines until another bowl!")
- end
- else
- print("Keep coding! Only " .. lines_per_bowl .. " more lines before another bowl!")
- write(dataFile, current)
- end
- end
- main({ ... })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement