Operating system for OpenComputers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3KB

  1. #!/usr/bin/env lua
  2. local doc = require "lib/doc"
  3. local tA = {...}
  4. local outpath = table.remove(tA,1)
  5. print(outpath)
  6. local function formatDocs(fd)
  7. local rs = ""
  8. for name,finfo in pairs(fd) do
  9. if rs:len() > 0 then
  10. rs = rs .. "\n\n"
  11. end
  12. local as = ""
  13. for k,v in pairs(finfo.args) do
  14. if k > 1 then
  15. as = as .. ", "
  16. end
  17. as = as .. v[1]
  18. if v[2] then
  19. as = as .. "^"..v[2].."^"
  20. end
  21. end
  22. local rt = ""
  23. for k,v in pairs(finfo.outtypes or {}) do
  24. if rt:len() > 0 then
  25. rt = rt .. ", "
  26. else
  27. rt = ": "
  28. end
  29. rt = rt .. v
  30. end
  31. rs = string.format("%s## %s(%s)%s\n%s",rs,name,as,rt,finfo.description)
  32. end
  33. return rs
  34. end
  35. os.execute("sh -c 'mkdir -p "..outpath .. "'")
  36. if outpath:sub(#outpath) == "/" then outpath = outpath:sub(1, #outpath - 1) end
  37. local ad = io.open(outpath.."/apidoc.md","w")
  38. for k,v in pairs(tA) do
  39. local fd = doc.parsefile(v)
  40. local ds = formatDocs(fd)
  41. print(string.format("%s: %i",v,ds:len()))
  42. if ds and ds:len() > 0 then
  43. os.execute("sh -c 'mkdir -p $(dirname \""..outpath.."/"..v.."\")'")
  44. local f = io.open(outpath.."/"..v:gsub("%.lua$",".md"),"wb")
  45. f:write(string.format("# %s\n\n",v))
  46. f:write(ds)
  47. f:write("\n\n")
  48. f:close()
  49. ad:write(string.format("# %s\n\n",v))
  50. ad:write(ds)
  51. ad:write("\n\n")
  52. end
  53. end
  54. ad:close()