fix: remove variables heading if there is none, account for global in new module doc format

dev
TorchedSammy 2021-11-22 19:20:57 -05:00
parent f741c2709c
commit 4e244e141f
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 18 additions and 14 deletions

View File

@ -51,10 +51,7 @@ commander.register('doc', function(args)
These are the global Hilbish functions that are always available and not part of a module.]] These are the global Hilbish functions that are always available and not part of a module.]]
local modDocFormat = [[ local modDocFormat = [[
%s %s
# Variables
%s %s
# Functions # Functions
]] ]]
@ -85,11 +82,6 @@ These are the global Hilbish functions that are always available and not part of
end end
end end
if not f then
print('Could not find docs for module named ' .. mod .. '.')
return 1
end
if not funcdocs then if not funcdocs then
funcdocs = f:read '*a' funcdocs = f:read '*a'
end end
@ -105,12 +97,24 @@ These are the global Hilbish functions that are always available and not part of
end end
end)) end))
if ok then if mod == 'global' or ok then
local modmt = getmetatable(require(mod)) local props = {}
local props = table.map(modmt.__docProp, function(v, k) local propstr = ''
return lunacolors.underline(lunacolors.blue(k)) .. ' > ' .. v local modDesc = globalDesc
end) if ok then
desc = string.format(modDocFormat, (mod == 'global' and globalDesc or modmt.__doc), table.concat(props, "\n")) local modmt = getmetatable(require(mod))
modDesc = modmt.__doc
if modmt.__docProp then
-- not all modules have docs for properties
props = table.map(modmt.__docProp, function(v, k)
return lunacolors.underline(lunacolors.blue(k)) .. ' > ' .. v
end)
end
end
if #props > 0 then
propstr = '\n# Properties\n' .. table.concat(props, '\n') .. '\n'
end
desc = string.format(modDocFormat, modDesc, propstr)
end end
print(desc .. formattedFuncs) print(desc .. formattedFuncs)
f:close() f:close()