local usage = function()
io.write('\nUSAGE: sscan run scan_folder.lua <pattern> <path/to/folder>\n')
io.write(' Scan all subfiles for <pattern>, a Lua regex pattern.\n\n')
end
if #arg ~= 2 then usage() return 1 end
local scan_pattern = arg[1]
local scan_folder = arg[2]
user_engines:register(
'match_pattern',
function(p) return string.find(p, scan_pattern) ~= nil end)
if not fs:test(scan_folder) and scan_folder.type == 'directory' then
local err_msg = string.format(
'Error: expected directory, got %s\n', scan_folder.type)
io.write(err_msg)
return 1
end
local entries = fs:walk(scan_folder)
for _,entry in ipairs(entries)
do
if entry.type == 'file' then queue:add_file(entry.path) end
end
io.write(string.format('There are %d files in the scan queue.\n', #queue))
io.write(string.format('Starting scan for pattern: %s\n', scan_pattern))
local results = scanmgr:scan()
io.write(string.format('Scan found %d matching files.\n', #results))
for _,result in ipairs(results)
do
local result = string.format(
'Engine %q matched file %q (%q)\n',
result.engine, result.item.name, result.item.path)
io.write(result)
end