From 4e244e141f561eb336b0ca430ebef6aef4e5a086 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:20:57 -0500 Subject: [PATCH] fix: remove variables heading if there is none, account for global in new module doc format --- preload.lua | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/preload.lua b/preload.lua index 5d14e0d..fff19b3 100644 --- a/preload.lua +++ b/preload.lua @@ -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.]] local modDocFormat = [[ %s - -# Variables %s - # Functions ]] @@ -85,11 +82,6 @@ These are the global Hilbish functions that are always available and not part of end end - if not f then - print('Could not find docs for module named ' .. mod .. '.') - return 1 - end - if not funcdocs then funcdocs = f:read '*a' end @@ -105,12 +97,24 @@ These are the global Hilbish functions that are always available and not part of end end)) - if ok then - local modmt = getmetatable(require(mod)) - local props = table.map(modmt.__docProp, function(v, k) - return lunacolors.underline(lunacolors.blue(k)) .. ' > ' .. v - end) - desc = string.format(modDocFormat, (mod == 'global' and globalDesc or modmt.__doc), table.concat(props, "\n")) + if mod == 'global' or ok then + local props = {} + local propstr = '' + local modDesc = globalDesc + if ok then + 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 print(desc .. formattedFuncs) f:close()