-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpinky
executable file
·41 lines (33 loc) · 999 Bytes
/
pinky
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
#!/usr/bin/env lua
package.cpath = package.cpath .. ";" .. os.getenv("HOME") .. "/.luarocks/lib/lua/5.1/?.so;;"
package.path = package.path .. ";" .. os.getenv("HOME") .. "/.luarocks/share/lua/5.1/?.lua;;"
local p = require 'pinky'
if #arg < 1 then
return print("Usage: pinky <uri>")
end
function print_table(in_table)
local out2 = ""
for k,v in pairs(in_table) do
out2 = out2 .. " " .. k -- .. " " .. v
end
print(out2)
end
local uri = arg[1]
if not string.find(uri,"^/pinky/") then
uri = string.gsub("/pinky/" .. uri,"//","/")
end
out = p.dispatch(uri)
if type(out) == "table" then
print("XXX FIXME: " .. uri .. " is not sending me json back!")
if out.status then
if out.status.value == "FAIL" then
print("msg:" .. tostring(out.status.error) .. " data:" .. tostring(out.data))
else
print_table(out.data)
end
else
print("Got nil back on out.status: " .. tostring(out.status))
end
else
print(tostring(out))
end