Skip to content

Commit

Permalink
Auto-generate man file
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Mar 5, 2024
1 parent f976c43 commit cecb626
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 91 deletions.
41 changes: 41 additions & 0 deletions build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,47 @@ function tag_hook(tagname)
os.execute('git commit -a -m "Step release tag"')
end

-- Auto-generate a .1 file from the help
function docinit_hook()
local find = string.find
local insert = table.insert
local open = io.open

local f = open("README.md","rb")
local readme = f:read("*all")
local date_start,date_end = find(readme,"%d%d%d%d%p%d%d%p%d%d")

local man_t = {}
insert(man_t,'.TH ' .. string.upper(module) .. ' 1 "'
.. readme:sub(date_start,date_end) .. '" "LaTeX"\n')
insert(man_t,(".SH NAME\n" .. module .. "\n"))
insert(man_t,(".SH SYNOPSIS\n Usage " .. module .. " <cmd> [<options>] [<names>]\n"))
insert(man_t,".SH DESCRIPTION")

local _,desc_start = find(readme,"Overview\n--------")
local desc_end,_ = find(readme,"Issues")

local overview = readme:sub(desc_start + 2,desc_end - 2):gsub("[`_]","")
insert(man_t,overview)

local cmd = "texlua ./" .. module .. ".lua --help"
local f = assert(io.popen(cmd,"r"))
local help_text = assert(f:read("*a"))
f:close()

insert(man_t,(help_text:gsub("\nUsage.*spec>]\n\n","")
:gsub("Valid commands",".SH COMMANDS\nValid commands")
:gsub("Valid options",".SH OPTIONS\nValid options")
:gsub("Full manual",'.SH "SEE ALSO"\nFull manual')
:gsub("Bug tracker","\nBug tracker")
:gsub("Copyright",".SH AUTHORS\nCopyright")))

f = assert(open(module .. ".1","wb"))
f:write((table.concat(man_t,"\n"):gsub("\n$","")))
f:close()
return 0
end

if not release_date then
dofile("./l3build.lua")
end
91 changes: 0 additions & 91 deletions l3build.1

This file was deleted.

0 comments on commit cecb626

Please sign in to comment.