-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.lua
More file actions
48 lines (41 loc) · 1.07 KB
/
help.lua
File metadata and controls
48 lines (41 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local expect = require "cc.expect"
local fs = require "fs"
local help = {}
local path = "/usr/share/man/*:/usr/local/share/man/*"
function help.path()
return path
end
function help.setPath(newPath)
expect(1, newPath, "string")
path = newPath
end
function help.lookup(topic)
expect(1, topic, "string")
for p in path:gmatch "[^:]+" do
local t = fs.find(fs.combine(p, topic .. ".*"))
if #t > 0 then return table.unpack(t) end
end
return nil
end
function help.topics()
local retval = {}
for p in path:gmatch "[^:]+" do
for dir in ipairs(fs.find(p)) do
for _, v in ipairs(fs.list(dir)) do
retval[#retval+1] = v:gsub("%..*$", "")
end
end
end
return retval
end
function help.completeTopic(topic)
expect(1, topic, "string")
local retval = {}
for p in path:gmatch "[^:]+" do
for _, v in ipairs(fs.find(fs.combine(p, topic .. "*"))) do
retval[#retval+1] = v:match(topic .. "([^/%.]+)%.?[^/]*$")
end
end
return retval
end
return help