repos.flua
· 488 B · Text
Raw
#!/usr/libexec/flua
-- usage - chmod, then `pkg repositories | repos.flua`
local ucl = require("ucl")
local parser = ucl.parser()
-- read from stdin
local data = io.stdin:read("*all")
-- try to convert to lua table
local ok, err = parser:parse_string(data)
if not ok then
io.stderr:write("Error parsing UCL: " .. err .. "\n")
os.exit(1)
end
-- fetch the root object
data = parser:get_object()
-- pretty-print the lua table as json
print(ucl.to_format(data, "json"))
| 1 | #!/usr/libexec/flua |
| 2 | |
| 3 | -- usage - chmod, then `pkg repositories | repos.flua` |
| 4 | |
| 5 | local ucl = require("ucl") |
| 6 | local parser = ucl.parser() |
| 7 | |
| 8 | -- read from stdin |
| 9 | local data = io.stdin:read("*all") |
| 10 | |
| 11 | -- try to convert to lua table |
| 12 | local ok, err = parser:parse_string(data) |
| 13 | |
| 14 | if not ok then |
| 15 | io.stderr:write("Error parsing UCL: " .. err .. "\n") |
| 16 | os.exit(1) |
| 17 | end |
| 18 | |
| 19 | -- fetch the root object |
| 20 | data = parser:get_object() |
| 21 | |
| 22 | -- pretty-print the lua table as json |
| 23 | print(ucl.to_format(data, "json")) |