#!/usr/bin/lilush local lilpack = require("lilpack") lilpack.init() local argparser = require("argparser") local markdown = require("markdown") local liman = require("liman") local scanner = require("liman.scanner") local wiki = require("liman.wiki") local export = require("liman.export") local home = os.getenv("HOME") or "/tmp" local parser = argparser.command("liman") parser:summary("Generate documentation from Lua source files using LIMAN doc comments.") parser:command("wiki", function(sub) sub:summary("Generate a Wiki-DB MNEME database from doc comments") sub:option("output", { short = "o", type = "string", default = home .. "/.local/share/lilush/wiki/liman.mneme", note = "Output .mneme file path", }) sub:option("title", { short = "t", type = "string", default = "Lilush API Reference", note = "Wiki title", }) sub:option("description", { short = "d", type = "string", default = "Module and function documentation for the lilush runtime", note = "Wiki description", }) sub:argument("dirs", { type = "dir", nargs = "+", note = "Source directories to scan for doc comments", }) end) parser:command("export", function(sub) sub:summary("Generate docs.lua for RELIW serving") sub:option("output", { short = "o", type = "string", default = "docs.lua", note = "Output file path", }) sub:argument("dirs", { type = "dir", nargs = "+", note = "Source directories to scan for doc comments", }) end) local parsed, err = parser:parse(arg) if err then local msg = argparser.format_error(err) if err.kind == "help" then io.stderr:write("\n" .. markdown.render(msg).rendered .. "\n") os.exit(0) end io.stderr:write(markdown.render(msg).rendered) os.exit(1) end local sub = parsed.subcommand local sa = parsed.args local docs, warnings = scanner.scan(sa.dirs) for _, w in ipairs(warnings) do io.stderr:write("[liman] WARNING: " .. w .. "\n") end if sub == "wiki" then local mod_count, func_count = wiki.generate(docs, sa.output, { title = sa.title, description = sa.description, }) if not mod_count then io.stderr:write("[liman] ERROR: " .. tostring(func_count) .. "\n") os.exit(1) end io.stderr:write( string.format("[liman] Generated wiki-db: %d modules, %d functions -> %s\n", mod_count, func_count, sa.output) ) elseif sub == "export" then local mod_count, err = export.generate(docs, sa.output) if not mod_count then io.stderr:write("[liman] ERROR: " .. tostring(err) .. "\n") os.exit(1) end io.stderr:write(string.format("[liman] Generated %s (%d modules)\n", sa.output, mod_count)) end