1
0

InfoDump: Fixed GH permission export, moved output to plugins.

This commit is contained in:
Mattes D 2014-10-18 20:51:28 +02:00
parent 687752241f
commit e2c1b86839

View File

@ -20,8 +20,8 @@ only that one plugin's documentation. This mode of operation doesn't require Lua
-- Check Lua version. We use 5.1-specific construct when loading the plugin info, 5.2 is not compatible! -- Check Lua version. We use 5.1-specific construct when loading the plugin info, 5.2 is not compatible!
if (_VERSION ~= "Lua 5.1") then if (_VERSION ~= "Lua 5.1") then
print("Unsupported Lua version. This script requires Lua version 5.1, this Lua is version " .. (_VERSION or "<nil>")); print("Unsupported Lua version. This script requires Lua version 5.1, this Lua is version " .. (_VERSION or "<nil>"))
return; return
end end
@ -31,38 +31,38 @@ end
--- Replaces generic formatting with forum-specific formatting --- Replaces generic formatting with forum-specific formatting
-- Also removes the single line-ends -- Also removes the single line-ends
local function ForumizeString(a_Str) local function ForumizeString(a_Str)
assert(type(a_Str) == "string"); assert(type(a_Str) == "string")
-- Remove the indentation, unless in the code tag: -- Remove the indentation, unless in the code tag:
-- Only one code or /code tag per line is supported! -- Only one code or /code tag per line is supported!
local IsInCode = false; local IsInCode = false
local function RemoveIndentIfNotInCode(s) local function RemoveIndentIfNotInCode(s)
if (IsInCode) then if (IsInCode) then
-- we're in code section, check if this line terminates it -- we're in code section, check if this line terminates it
IsInCode = (s:find("{%%/code}") ~= nil); IsInCode = (s:find("{%%/code}") ~= nil)
return s .. "\n"; return s .. "\n"
else else
-- we're not in code section, check if this line starts it -- we're not in code section, check if this line starts it
IsInCode = (s:find("{%%code}") ~= nil); IsInCode = (s:find("{%%code}") ~= nil)
return s:gsub("^%s*", "") .. "\n"; return s:gsub("^%s*", "") .. "\n"
end end
end end
a_Str = a_Str:gsub("(.-)\n", RemoveIndentIfNotInCode); a_Str = a_Str:gsub("(.-)\n", RemoveIndentIfNotInCode)
-- Replace multiple line ends with {%p} and single line ends with a space, -- Replace multiple line ends with {%p} and single line ends with a space,
-- so that manual word-wrap in the Info.lua file doesn't wrap in the forum. -- so that manual word-wrap in the Info.lua file doesn't wrap in the forum.
a_Str = a_Str:gsub("\n\n", "{%%p}"); a_Str = a_Str:gsub("\n\n", "{%%p}")
a_Str = a_Str:gsub("\n", " "); a_Str = a_Str:gsub("\n", " ")
-- Replace the generic formatting: -- Replace the generic formatting:
a_Str = a_Str:gsub("{%%p}", "\n\n"); a_Str = a_Str:gsub("{%%p}", "\n\n")
a_Str = a_Str:gsub("{%%b}", "[b]"):gsub("{%%/b}", "[/b]"); a_Str = a_Str:gsub("{%%b}", "[b]"):gsub("{%%/b}", "[/b]")
a_Str = a_Str:gsub("{%%i}", "[i]"):gsub("{%%/i}", "[/i]"); a_Str = a_Str:gsub("{%%i}", "[i]"):gsub("{%%/i}", "[/i]")
a_Str = a_Str:gsub("{%%list}", "[list]"):gsub("{%%/list}", "[/list]"); a_Str = a_Str:gsub("{%%list}", "[list]"):gsub("{%%/list}", "[/list]")
a_Str = a_Str:gsub("{%%li}", "[*]"):gsub("{%%/li}", ""); a_Str = a_Str:gsub("{%%li}", "[*]"):gsub("{%%/li}", "")
-- TODO: Other formatting -- TODO: Other formatting
return a_Str; return a_Str
end end
@ -72,38 +72,38 @@ end
--- Replaces generic formatting with forum-specific formatting --- Replaces generic formatting with forum-specific formatting
-- Also removes the single line-ends -- Also removes the single line-ends
local function GithubizeString(a_Str) local function GithubizeString(a_Str)
assert(type(a_Str) == "string"); assert(type(a_Str) == "string")
-- Remove the indentation, unless in the code tag: -- Remove the indentation, unless in the code tag:
-- Only one code or /code tag per line is supported! -- Only one code or /code tag per line is supported!
local IsInCode = false; local IsInCode = false
local function RemoveIndentIfNotInCode(s) local function RemoveIndentIfNotInCode(s)
if (IsInCode) then if (IsInCode) then
-- we're in code section, check if this line terminates it -- we're in code section, check if this line terminates it
IsInCode = (s:find("{%%/code}") ~= nil); IsInCode = (s:find("{%%/code}") ~= nil)
return s .. "\n"; return s .. "\n"
else else
-- we're not in code section, check if this line starts it -- we're not in code section, check if this line starts it
IsInCode = (s:find("{%%code}") ~= nil); IsInCode = (s:find("{%%code}") ~= nil)
return s:gsub("^%s*", "") .. "\n"; return s:gsub("^%s*", "") .. "\n"
end end
end end
a_Str = a_Str:gsub("(.-)\n", RemoveIndentIfNotInCode); a_Str = a_Str:gsub("(.-)\n", RemoveIndentIfNotInCode)
-- Replace multiple line ends with {%p} and single line ends with a space, -- Replace multiple line ends with {%p} and single line ends with a space,
-- so that manual word-wrap in the Info.lua file doesn't wrap in the forum. -- so that manual word-wrap in the Info.lua file doesn't wrap in the forum.
a_Str = a_Str:gsub("\n\n", "{%%p}"); a_Str = a_Str:gsub("\n\n", "{%%p}")
a_Str = a_Str:gsub("\n", " "); a_Str = a_Str:gsub("\n", " ")
-- Replace the generic formatting: -- Replace the generic formatting:
a_Str = a_Str:gsub("{%%p}", "\n\n"); a_Str = a_Str:gsub("{%%p}", "\n\n")
a_Str = a_Str:gsub("{%%b}", "**"):gsub("{%%/b}", "**"); a_Str = a_Str:gsub("{%%b}", "**"):gsub("{%%/b}", "**")
a_Str = a_Str:gsub("{%%i}", "*"):gsub("{%%/i}", "*"); a_Str = a_Str:gsub("{%%i}", "*"):gsub("{%%/i}", "*")
a_Str = a_Str:gsub("{%%list}", ""):gsub("{%%/list}", ""); a_Str = a_Str:gsub("{%%list}", ""):gsub("{%%/list}", "")
a_Str = a_Str:gsub("{%%li}", " - "):gsub("{%%/li}", ""); a_Str = a_Str:gsub("{%%li}", " - "):gsub("{%%/li}", "")
-- TODO: Other formatting -- TODO: Other formatting
return a_Str; return a_Str
end end
@ -117,7 +117,7 @@ end
local function BuildCategories(a_PluginInfo) local function BuildCategories(a_PluginInfo)
-- The returned result -- The returned result
-- This will contain both an array and a dict of the categories, to allow fast search -- This will contain both an array and a dict of the categories, to allow fast search
local res = {}; local res = {}
-- For each command add a reference to it into all of its categories: -- For each command add a reference to it into all of its categories:
local function AddCommands(a_CmdPrefix, a_Commands) local function AddCommands(a_CmdPrefix, a_Commands)
@ -130,39 +130,39 @@ local function BuildCategories(a_PluginInfo)
if ((info.HelpString ~= nil) and (info.HelpString ~= "")) then if ((info.HelpString ~= nil) and (info.HelpString ~= "")) then
-- Add to each specified category: -- Add to each specified category:
local Category = info.Category; local Category = info.Category
if (type(Category) == "string") then if (type(Category) == "string") then
Category = {Category}; Category = {Category}
end end
for idx, cat in ipairs(Category or {""}) do for idx, cat in ipairs(Category or {""}) do
local CatEntry = res[cat]; local CatEntry = res[cat]
if (CatEntry == nil) then if (CatEntry == nil) then
-- First time we came across this category, create it: -- First time we came across this category, create it:
local NewCat = {Name = cat, Description = "", Commands = {NewCmd}}; local NewCat = {Name = cat, Description = "", Commands = {NewCmd}}
table.insert(res, NewCat); table.insert(res, NewCat)
res[cat] = NewCat; res[cat] = NewCat
else else
-- We already have this category, just add the command to its list of commands: -- We already have this category, just add the command to its list of commands:
table.insert(CatEntry.Commands, NewCmd); table.insert(CatEntry.Commands, NewCmd)
end end
end -- for idx, cat - Category[] end -- for idx, cat - Category[]
end -- if (HelpString valid) end -- if (HelpString valid)
-- Recurse all subcommands: -- Recurse all subcommands:
if (info.Subcommands ~= nil) then if (info.Subcommands ~= nil) then
AddCommands(a_CmdPrefix .. cmd .. " ", info.Subcommands); AddCommands(a_CmdPrefix .. cmd .. " ", info.Subcommands)
end end
end -- for cmd, info - a_Commands[] end -- for cmd, info - a_Commands[]
end -- AddCommands() end -- AddCommands()
AddCommands("", a_PluginInfo.Commands); AddCommands("", a_PluginInfo.Commands)
-- Assign descriptions to categories: -- Assign descriptions to categories:
for name, desc in pairs(a_PluginInfo.Categories or {}) do for name, desc in pairs(a_PluginInfo.Categories or {}) do
local CatEntry = res[name]; local CatEntry = res[name]
if (CatEntry ~= nil) then if (CatEntry ~= nil) then
-- The result has this category, add the description: -- The result has this category, add the description:
CatEntry.Description = desc.Description; CatEntry.Description = desc.Description
end end
end end
@ -170,12 +170,12 @@ local function BuildCategories(a_PluginInfo)
for idx, cat in ipairs(res) do for idx, cat in ipairs(res) do
table.sort(cat.Commands, table.sort(cat.Commands,
function (cmd1, cmd2) function (cmd1, cmd2)
return (string.lower(cmd1.CommandString) < string.lower(cmd2.CommandString)); return (string.lower(cmd1.CommandString) < string.lower(cmd2.CommandString))
end end
); )
end end
return res; return res
end end
@ -188,9 +188,9 @@ end
-- colorizes command name blue and params green -- colorizes command name blue and params green
local function GetCommandRefForum(a_Command) local function GetCommandRefForum(a_Command)
if (type(a_Command) == "string") then if (type(a_Command) == "string") then
return "[color=blue]" .. a_Command .. "[/color]"; return "[color=blue]" .. a_Command .. "[/color]"
end end
return "[color=blue]" .. a_Command.Name .. "[/color] [color=green]" .. (a_Command.Params or "") .. "[/color]"; return "[color=blue]" .. a_Command.Name .. "[/color] [color=green]" .. (a_Command.Params or "") .. "[/color]"
end end
@ -201,18 +201,18 @@ end
-- If a_CommandParams is nil, returns a_CommandName apostrophed -- If a_CommandParams is nil, returns a_CommandName apostrophed
-- If a_CommandParams is a string, apostrophes a_CommandName with a_CommandParams -- If a_CommandParams is a string, apostrophes a_CommandName with a_CommandParams
local function GetCommandRefGithub(a_CommandName, a_CommandParams) local function GetCommandRefGithub(a_CommandName, a_CommandParams)
assert(type(a_CommandName) == "string"); assert(type(a_CommandName) == "string")
if (a_CommandParams == nil) then if (a_CommandParams == nil) then
return "`" .. a_CommandName .. "`"; return "`" .. a_CommandName .. "`"
end end
assert(type(a_CommandParams) == "table"); assert(type(a_CommandParams) == "table")
if ((a_CommandParams.Params == nil) or (a_CommandParams.Params == "")) then if ((a_CommandParams.Params == nil) or (a_CommandParams.Params == "")) then
return "`" .. a_CommandName .. "`"; return "`" .. a_CommandName .. "`"
end end
assert(type(a_CommandParams.Params) == "string"); assert(type(a_CommandParams.Params) == "string")
return "`" .. a_CommandName .. " " .. a_CommandParams.Params .. "`"; return "`" .. a_CommandName .. " " .. a_CommandParams.Params .. "`"
end end
@ -221,25 +221,25 @@ end
--- Writes the specified command detailed help array to the output file, in the forum dump format --- Writes the specified command detailed help array to the output file, in the forum dump format
local function WriteCommandParameterCombinationsForum(a_CmdString, a_ParameterCombinations, f) local function WriteCommandParameterCombinationsForum(a_CmdString, a_ParameterCombinations, f)
assert(type(a_CmdString) == "string"); assert(type(a_CmdString) == "string")
assert(type(a_ParameterCombinations) == "table"); assert(type(a_ParameterCombinations) == "table")
assert(f ~= nil); assert(f ~= nil)
if (#a_ParameterCombinations == 0) then if (#a_ParameterCombinations == 0) then
-- No explicit parameter combinations to write -- No explicit parameter combinations to write
return; return
end end
f:write("The following parameter combinations are recognized:\n"); f:write("The following parameter combinations are recognized:\n")
for idx, combination in ipairs(a_ParameterCombinations) do for idx, combination in ipairs(a_ParameterCombinations) do
f:write("[color=blue]", a_CmdString, "[/color] [color=green]", combination.Params or "", "[/color]"); f:write("[color=blue]", a_CmdString, "[/color] [color=green]", combination.Params or "", "[/color]")
if (combination.Help ~= nil) then if (combination.Help ~= nil) then
f:write(" - ", ForumizeString(combination.Help)); f:write(" - ", ForumizeString(combination.Help))
end end
if (combination.Permission ~= nil) then if (combination.Permission ~= nil) then
f:write(" (Requires permission '[color=red]", combination.Permission, "[/color]')"); f:write(" (Requires permission '[color=red]", combination.Permission, "[/color]')")
end end
f:write("\n"); f:write("\n")
end end
end end
@ -249,25 +249,25 @@ end
--- Writes the specified command detailed help array to the output file, in the forum dump format --- Writes the specified command detailed help array to the output file, in the forum dump format
local function WriteCommandParameterCombinationsGithub(a_CmdString, a_ParameterCombinations, f) local function WriteCommandParameterCombinationsGithub(a_CmdString, a_ParameterCombinations, f)
assert(type(a_CmdString) == "string"); assert(type(a_CmdString) == "string")
assert(type(a_ParameterCombinations) == "table"); assert(type(a_ParameterCombinations) == "table")
assert(f ~= nil); assert(f ~= nil)
if (#a_ParameterCombinations == 0) then if (#a_ParameterCombinations == 0) then
-- No explicit parameter combinations to write -- No explicit parameter combinations to write
return; return
end end
f:write("The following parameter combinations are recognized:\n\n"); f:write("The following parameter combinations are recognized:\n\n")
for idx, combination in ipairs(a_ParameterCombinations) do for idx, combination in ipairs(a_ParameterCombinations) do
f:write(GetCommandRefGithub(a_CmdString, combination)); f:write(GetCommandRefGithub(a_CmdString, combination))
if (combination.Help ~= nil) then if (combination.Help ~= nil) then
f:write(" - ", GithubizeString(combination.Help)); f:write(" - ", GithubizeString(combination.Help))
end end
if (combination.Permission ~= nil) then if (combination.Permission ~= nil) then
f:write(" (Requires permission '**", combination.Permission, "**')"); f:write(" (Requires permission '**", combination.Permission, "**')")
end end
f:write("\n"); f:write("\n")
end end
end end
@ -278,29 +278,29 @@ end
--- Writes all commands in the specified category to the output file, in the forum dump format --- Writes all commands in the specified category to the output file, in the forum dump format
local function WriteCommandsCategoryForum(a_Category, f) local function WriteCommandsCategoryForum(a_Category, f)
-- Write category name: -- Write category name:
local CategoryName = a_Category.Name; local CategoryName = a_Category.Name
if (CategoryName == "") then if (CategoryName == "") then
CategoryName = "General"; CategoryName = "General"
end end
f:write("\n[size=Large]", ForumizeString(a_Category.DisplayName or CategoryName), "[/size]\n"); f:write("\n[size=Large]", ForumizeString(a_Category.DisplayName or CategoryName), "[/size]\n")
-- Write description: -- Write description:
if (a_Category.Description ~= "") then if (a_Category.Description ~= "") then
f:write(ForumizeString(a_Category.Description), "\n"); f:write(ForumizeString(a_Category.Description), "\n")
end end
-- Write commands: -- Write commands:
f:write("\n[list]"); f:write("\n[list]")
for idx2, cmd in ipairs(a_Category.Commands) do for idx2, cmd in ipairs(a_Category.Commands) do
f:write("\n[b]", cmd.CommandString, "[/b] - ", ForumizeString(cmd.Info.HelpString or "UNDOCUMENTED"), "\n"); f:write("\n[b]", cmd.CommandString, "[/b] - ", ForumizeString(cmd.Info.HelpString or "UNDOCUMENTED"), "\n")
if (cmd.Info.Permission ~= nil) then if (cmd.Info.Permission ~= nil) then
f:write("Permission required: [color=red]", cmd.Info.Permission, "[/color]\n"); f:write("Permission required: [color=red]", cmd.Info.Permission, "[/color]\n")
end end
if (cmd.Info.DetailedDescription ~= nil) then if (cmd.Info.DetailedDescription ~= nil) then
f:write(ForumizeString(cmd.Info.DetailedDescription)); f:write(ForumizeString(cmd.Info.DetailedDescription))
end end
if (cmd.Info.ParameterCombinations ~= nil) then if (cmd.Info.ParameterCombinations ~= nil) then
WriteCommandParameterCombinationsForum(cmd.CommandString, cmd.Info.ParameterCombinations, f); WriteCommandParameterCombinationsForum(cmd.CommandString, cmd.Info.ParameterCombinations, f)
end end
end end
f:write("[/list]\n\n") f:write("[/list]\n\n")
@ -313,15 +313,15 @@ end
--- Writes all commands in the specified category to the output file, in the Github dump format --- Writes all commands in the specified category to the output file, in the Github dump format
local function WriteCommandsCategoryGithub(a_Category, f) local function WriteCommandsCategoryGithub(a_Category, f)
-- Write category name: -- Write category name:
local CategoryName = a_Category.Name; local CategoryName = a_Category.Name
if (CategoryName == "") then if (CategoryName == "") then
CategoryName = "General"; CategoryName = "General"
end end
f:write("\n### ", GithubizeString(a_Category.DisplayName or CategoryName), "\n"); f:write("\n### ", GithubizeString(a_Category.DisplayName or CategoryName), "\n")
-- Write description: -- Write description:
if (a_Category.Description ~= "") then if (a_Category.Description ~= "") then
f:write(GithubizeString(a_Category.Description), "\n\n"); f:write(GithubizeString(a_Category.Description), "\n\n")
end end
f:write("| Command | Permission | Description | \n") f:write("| Command | Permission | Description | \n")
@ -340,24 +340,24 @@ end
local function DumpCommandsForum(a_PluginInfo, f) local function DumpCommandsForum(a_PluginInfo, f)
-- Copy all Categories from a dictionary into an array: -- Copy all Categories from a dictionary into an array:
local Categories = BuildCategories(a_PluginInfo); local Categories = BuildCategories(a_PluginInfo)
-- Sort the categories by name: -- Sort the categories by name:
table.sort(Categories, table.sort(Categories,
function(cat1, cat2) function(cat1, cat2)
return (string.lower(cat1.Name) < string.lower(cat2.Name)); return (string.lower(cat1.Name) < string.lower(cat2.Name))
end end
); )
if (#Categories == 0) then if (#Categories == 0) then
return; return
end end
f:write("\n[size=X-Large]Commands[/size]\n"); f:write("\n[size=X-Large]Commands[/size]\n")
-- Dump per-category commands: -- Dump per-category commands:
for idx, cat in ipairs(Categories) do for idx, cat in ipairs(Categories) do
WriteCommandsCategoryForum(cat, f); WriteCommandsCategoryForum(cat, f)
end end
end end
@ -367,24 +367,24 @@ end
local function DumpCommandsGithub(a_PluginInfo, f) local function DumpCommandsGithub(a_PluginInfo, f)
-- Copy all Categories from a dictionary into an array: -- Copy all Categories from a dictionary into an array:
local Categories = BuildCategories(a_PluginInfo); local Categories = BuildCategories(a_PluginInfo)
-- Sort the categories by name: -- Sort the categories by name:
table.sort(Categories, table.sort(Categories,
function(cat1, cat2) function(cat1, cat2)
return (string.lower(cat1.Name) < string.lower(cat2.Name)); return (string.lower(cat1.Name) < string.lower(cat2.Name))
end end
); )
if (#Categories == 0) then if (#Categories == 0) then
return; return
end end
f:write("\n# Commands\n"); f:write("\n# Commands\n")
-- Dump per-category commands: -- Dump per-category commands:
for idx, cat in ipairs(Categories) do for idx, cat in ipairs(Categories) do
WriteCommandsCategoryGithub(cat, f); WriteCommandsCategoryGithub(cat, f)
end end
end end
@ -393,16 +393,16 @@ end
local function DumpAdditionalInfoForum(a_PluginInfo, f) local function DumpAdditionalInfoForum(a_PluginInfo, f)
local AInfo = a_PluginInfo.AdditionalInfo; local AInfo = a_PluginInfo.AdditionalInfo
if (type(AInfo) ~= "table") then if (type(AInfo) ~= "table") then
-- There is no AdditionalInfo in a_PluginInfo -- There is no AdditionalInfo in a_PluginInfo
return; return
end end
for idx, info in ipairs(a_PluginInfo.AdditionalInfo) do for idx, info in ipairs(a_PluginInfo.AdditionalInfo) do
if ((info.Title ~= nil) and (info.Contents ~= nil)) then if ((info.Title ~= nil) and (info.Contents ~= nil)) then
f:write("\n[size=X-Large]", ForumizeString(info.Title), "[/size]\n"); f:write("\n[size=X-Large]", ForumizeString(info.Title), "[/size]\n")
f:write(ForumizeString(info.Contents), "\n"); f:write(ForumizeString(info.Contents), "\n")
end end
end end
end end
@ -412,16 +412,16 @@ end
local function DumpAdditionalInfoGithub(a_PluginInfo, f) local function DumpAdditionalInfoGithub(a_PluginInfo, f)
local AInfo = a_PluginInfo.AdditionalInfo; local AInfo = a_PluginInfo.AdditionalInfo
if (type(AInfo) ~= "table") then if (type(AInfo) ~= "table") then
-- There is no AdditionalInfo in a_PluginInfo -- There is no AdditionalInfo in a_PluginInfo
return; return
end end
for idx, info in ipairs(a_PluginInfo.AdditionalInfo) do for idx, info in ipairs(a_PluginInfo.AdditionalInfo) do
if ((info.Title ~= nil) and (info.Contents ~= nil)) then if ((info.Title ~= nil) and (info.Contents ~= nil)) then
f:write("\n# ", GithubizeString(info.Title), "\n"); f:write("\n# ", GithubizeString(info.Title), "\n")
f:write(GithubizeString(info.Contents), "\n"); f:write(GithubizeString(info.Contents), "\n")
end end
end end
end end
@ -434,53 +434,53 @@ end
-- Each array item is {Name = "PermissionName", Info = { PermissionInfo }} -- Each array item is {Name = "PermissionName", Info = { PermissionInfo }}
local function BuildPermissions(a_PluginInfo) local function BuildPermissions(a_PluginInfo)
-- Collect all used permissions from Commands, reference the commands that use the permission: -- Collect all used permissions from Commands, reference the commands that use the permission:
local Permissions = a_PluginInfo.Permissions or {}; local Permissions = a_PluginInfo.Permissions or {}
local function CollectPermissions(a_CmdPrefix, a_Commands) local function CollectPermissions(a_CmdPrefix, a_Commands)
for cmd, info in pairs(a_Commands) do for cmd, info in pairs(a_Commands) do
CommandString = a_CmdPrefix .. cmd; CommandString = a_CmdPrefix .. cmd
if ((info.Permission ~= nil) and (info.Permission ~= "")) then if ((info.Permission ~= nil) and (info.Permission ~= "")) then
-- Add the permission to the list of permissions: -- Add the permission to the list of permissions:
local Permission = Permissions[info.Permission] or {}; local Permission = Permissions[info.Permission] or {}
Permissions[info.Permission] = Permission; Permissions[info.Permission] = Permission
-- Add the command to the list of commands using this permission: -- Add the command to the list of commands using this permission:
Permission.CommandsAffected = Permission.CommandsAffected or {}; Permission.CommandsAffected = Permission.CommandsAffected or {}
table.insert(Permission.CommandsAffected, CommandString); table.insert(Permission.CommandsAffected, CommandString)
end end
-- Process the command param combinations for permissions: -- Process the command param combinations for permissions:
local ParamCombinations = info.ParameterCombinations or {}; local ParamCombinations = info.ParameterCombinations or {}
for idx, comb in ipairs(ParamCombinations) do for idx, comb in ipairs(ParamCombinations) do
if ((comb.Permission ~= nil) and (comb.Permission ~= "")) then if ((comb.Permission ~= nil) and (comb.Permission ~= "")) then
-- Add the permission to the list of permissions: -- Add the permission to the list of permissions:
local Permission = Permissions[comb.Permission] or {}; local Permission = Permissions[comb.Permission] or {}
Permissions[info.Permission] = Permission; Permissions[info.Permission] = Permission
-- Add the command to the list of commands using this permission: -- Add the command to the list of commands using this permission:
Permission.CommandsAffected = Permission.CommandsAffected or {}; Permission.CommandsAffected = Permission.CommandsAffected or {}
table.insert(Permission.CommandsAffected, {Name = CommandString, Params = comb.Params}); table.insert(Permission.CommandsAffected, {Name = CommandString, Params = comb.Params})
end end
end end
-- Process subcommands: -- Process subcommands:
if (info.Subcommands ~= nil) then if (info.Subcommands ~= nil) then
CollectPermissions(CommandString .. " ", info.Subcommands); CollectPermissions(CommandString .. " ", info.Subcommands)
end end
end end
end end
CollectPermissions("", a_PluginInfo.Commands); CollectPermissions("", a_PluginInfo.Commands)
-- Copy the list of permissions to an array: -- Copy the list of permissions to an array:
local PermArray = {}; local PermArray = {}
for name, perm in pairs(Permissions) do for name, perm in pairs(Permissions) do
table.insert(PermArray, {Name = name, Info = perm}); table.insert(PermArray, {Name = name, Info = perm})
end end
-- Sort the permissions array: -- Sort the permissions array:
table.sort(PermArray, table.sort(PermArray,
function(p1, p2) function(p1, p2)
return (p1.Name < p2.Name); return (p1.Name < p2.Name)
end end
); )
return PermArray; return PermArray
end end
@ -489,32 +489,32 @@ end
local function DumpPermissionsForum(a_PluginInfo, f) local function DumpPermissionsForum(a_PluginInfo, f)
-- Get the processed sorted array of permissions: -- Get the processed sorted array of permissions:
local Permissions = BuildPermissions(a_PluginInfo); local Permissions = BuildPermissions(a_PluginInfo)
if ((Permissions == nil) or (#Permissions <= 0)) then if ((Permissions == nil) or (#Permissions <= 0)) then
return; return
end end
-- Dump the permissions: -- Dump the permissions:
f:write("\n[size=X-Large]Permissions[/size]\n[list]\n"); f:write("\n[size=X-Large]Permissions[/size]\n[list]\n")
for idx, perm in ipairs(Permissions) do for idx, perm in ipairs(Permissions) do
f:write(" - [color=red]", perm.Name, "[/color] - "); f:write(" - [color=red]", perm.Name, "[/color] - ")
f:write(ForumizeString(perm.Info.Description or "")); f:write(ForumizeString(perm.Info.Description or ""))
local CommandsAffected = perm.Info.CommandsAffected or {}; local CommandsAffected = perm.Info.CommandsAffected or {}
if (#CommandsAffected > 0) then if (#CommandsAffected > 0) then
f:write("\n[list] Commands affected:\n- "); f:write("\n[list] Commands affected:\n- ")
local Affects = {}; local Affects = {}
for idx2, cmd in ipairs(CommandsAffected) do for idx2, cmd in ipairs(CommandsAffected) do
table.insert(Affects, GetCommandRefForum(cmd)); table.insert(Affects, GetCommandRefForum(cmd))
end end
f:write(table.concat(Affects, "\n - ")); f:write(table.concat(Affects, "\n - "))
f:write("\n[/list]"); f:write("\n[/list]")
end end
if (perm.Info.RecommendedGroups ~= nil) then if (perm.Info.RecommendedGroups ~= nil) then
f:write("\n[list] Recommended groups: ", perm.Info.RecommendedGroups, "[/list]"); f:write("\n[list] Recommended groups: ", perm.Info.RecommendedGroups, "[/list]")
end end
f:write("\n"); f:write("\n")
end end
f:write("[/list]"); f:write("[/list]")
end end
@ -523,34 +523,35 @@ end
local function DumpPermissionsGithub(a_PluginInfo, f) local function DumpPermissionsGithub(a_PluginInfo, f)
-- Get the processed sorted array of permissions: -- Get the processed sorted array of permissions:
local Permissions = BuildPermissions(a_PluginInfo); local Permissions = BuildPermissions(a_PluginInfo)
if ((Permissions == nil) or (#Permissions <= 0)) then if ((Permissions == nil) or (#Permissions <= 0)) then
return; return
end end
-- Dump the permissions: -- Dump the permissions:
f:write("\n# Permissions\n"); f:write("\n# Permissions\n")
f:write("| Permissions | Description | Commands | Recommended groups |\n") f:write("| Permissions | Description | Commands | Recommended groups |\n")
f:write("| ----------- | ----------- | -------- | ------------------ |\n") f:write("| ----------- | ----------- | -------- | ------------------ |\n")
for idx, perm in ipairs(Permissions) do for idx, perm in ipairs(Permissions) do
f:write(perm.Name, " | "); f:write("| ", perm.Name, " | ")
f:write(GithubizeString(perm.Info.Description or ""), " | "); f:write(GithubizeString(perm.Info.Description or ""), " | ")
local CommandsAffected = perm.Info.CommandsAffected or {}; local CommandsAffected = perm.Info.CommandsAffected or {}
if (#CommandsAffected > 0) then if (#CommandsAffected > 0) then
local Affects = {}; local Affects = {}
for idx2, cmd in ipairs(CommandsAffected) do for idx2, cmd in ipairs(CommandsAffected) do
if (type(cmd) == "string") then if (type(cmd) == "string") then
table.insert(Affects, GetCommandRefGithub(cmd)); table.insert(Affects, GetCommandRefGithub(cmd))
else else
table.insert(Affects, GetCommandRefGithub(cmd.Name, cmd)); table.insert(Affects, GetCommandRefGithub(cmd.Name, cmd))
end end
end end
f:write(table.concat(Affects, ", "), " | "); f:write(table.concat(Affects, ", "))
end end
f:write(" | ")
if (perm.Info.RecommendedGroups ~= nil) then if (perm.Info.RecommendedGroups ~= nil) then
f:write(perm.Info.RecommendedGroups, " |"); f:write(perm.Info.RecommendedGroups)
end end
f:write("\n"); f:write(" |\n")
end end
end end
@ -558,45 +559,53 @@ end
--- Dumps the forum-format info for the plugin
-- Returns true on success, nil and error message on failure
local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo) local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo)
-- Open the output file: -- Open the output file:
local f, msg = io.open(a_PluginInfo.Name .. "_forum.txt", "w"); local f, msg = io.open(a_PluginFolder .. "/forum_info.txt", "w")
if (f == nil) then if (f == nil) then
print("\tCannot dump forum info for plugin " .. a_PluginFolder .. ": " .. msg); return nil, msg
return;
end end
-- Write the description: -- Write the description:
f:write(ForumizeString(a_PluginInfo.Description), "\n"); f:write(ForumizeString(a_PluginInfo.Description), "\n")
DumpAdditionalInfoForum(a_PluginInfo, f); DumpAdditionalInfoForum(a_PluginInfo, f)
DumpCommandsForum(a_PluginInfo, f); DumpCommandsForum(a_PluginInfo, f)
DumpPermissionsForum(a_PluginInfo, f); DumpPermissionsForum(a_PluginInfo, f)
if (a_PluginInfo.SourceLocation ~= nil) then if (a_PluginInfo.SourceLocation ~= nil) then
f:write("[b][color=blue]Source:[/color] [url=", a_PluginInfo.SourceLocation, "]Link[/url][/b]"); f:write("[b][color=blue]Source:[/color] [url=", a_PluginInfo.SourceLocation, "]Link[/url][/b]")
end end
f:close()
f:close(); return true
end end
--- Dumps the README.md file into the plugin's folder with the GitHub Markdown format
-- Returns true on success, nil and error message on failure
local function DumpPluginInfoGithub(a_PluginFolder, a_PluginInfo) local function DumpPluginInfoGithub(a_PluginFolder, a_PluginInfo)
-- Check the params:
assert(type(a_PluginFolder) == "string")
assert(type(a_PluginInfo) == "table")
-- Open the output file: -- Open the output file:
local f, msg = io.open(a_PluginInfo.Name .. ".md", "w"); -- TODO: Save to a_PluginFolder .. "/Readme.md" instead local f, msg = io.open(a_PluginFolder .. "/README.md", "w")
if (f == nil) then if (f == nil) then
print("\tCannot dump github info for plugin " .. a_PluginFolder .. ": " .. msg); print("\tCannot dump github info for plugin " .. a_PluginFolder .. ": " .. msg)
return; return nil, msg
end end
-- Write the description: -- Write the description:
f:write(GithubizeString(a_PluginInfo.Description), "\n"); f:write(GithubizeString(a_PluginInfo.Description), "\n")
DumpAdditionalInfoGithub(a_PluginInfo, f); DumpAdditionalInfoGithub(a_PluginInfo, f)
DumpCommandsGithub(a_PluginInfo, f); DumpCommandsGithub(a_PluginInfo, f)
DumpPermissionsGithub(a_PluginInfo, f); DumpPermissionsGithub(a_PluginInfo, f)
f:close(); f:close()
return true
end end
@ -607,36 +616,50 @@ end
-- Returns the g_PluginInfo table on success, or nil and error message on failure -- Returns the g_PluginInfo table on success, or nil and error message on failure
local function LoadPluginInfo(a_FolderName) local function LoadPluginInfo(a_FolderName)
-- Load and compile the Info file: -- Load and compile the Info file:
local cfg, err = loadfile(a_FolderName .. "/Info.lua"); local cfg, err = loadfile(a_FolderName .. "/Info.lua")
if (cfg == nil) then if (cfg == nil) then
return nil, "Cannot open 'Info.lua': " .. err; return nil, "Cannot open 'Info.lua': " .. err
end end
-- Execute the loaded file in a sandbox: -- Execute the loaded file in a sandbox:
-- This is Lua-5.1-specific and won't work in Lua 5.2! -- This is Lua-5.1-specific and won't work in Lua 5.2!
local Sandbox = {}; local Sandbox = {}
setfenv(cfg, Sandbox); setfenv(cfg, Sandbox)
cfg(); cfg()
if (Sandbox.g_PluginInfo == nil) then if (Sandbox.g_PluginInfo == nil) then
return nil, "Info.lua doesn't contain the g_PluginInfo declaration"; return nil, "Info.lua doesn't contain the g_PluginInfo declaration"
end end
return Sandbox.g_PluginInfo; return Sandbox.g_PluginInfo
end end
--- Processes the info for one plugin
-- Returns true on success, nil and error message on failure
local function ProcessPluginFolder(a_FolderName) local function ProcessPluginFolder(a_FolderName)
local PluginInfo, Msg = LoadPluginInfo(a_FolderName); -- Load the plugin info:
local PluginInfo, Msg = LoadPluginInfo(a_FolderName)
if (PluginInfo == nil) then if (PluginInfo == nil) then
if (Msg ~= nil) then return nil, "Cannot load info for plugin " .. a_FolderName .. ": " .. (Msg or "<unknown error>")
print("\t" .. Msg);
end end
return;
-- Dump the forum format:
local isSuccess
isSuccess, Msg = DumpPluginInfoForum(a_FolderName, PluginInfo)
if not(isSuccess) then
return nil, "Cannot dump forum info for plugin " .. a_FolderName .. ": " .. (Msg or "<unknown error>")
end end
DumpPluginInfoForum(a_FolderName, PluginInfo);
DumpPluginInfoGithub(a_FolderName, PluginInfo); -- Dump the GitHub format:
isSuccess, Msg = DumpPluginInfoGithub(a_FolderName, PluginInfo)
if not(isSuccess) then
return nil, "Cannot dump GitHub info for plugin " .. a_FolderName .. ": " .. (Msg or "<unknown error>")
end
-- All OK, return success
return true
end end
@ -650,7 +673,7 @@ local function LoadLFS()
function() function()
return require("lfs") return require("lfs")
end end
); )
-- ... rather, print a nice message with instructions: -- ... rather, print a nice message with instructions:
if not(lfs) then if not(lfs) then
@ -663,44 +686,50 @@ local function LoadLFS()
If you don't have luarocks installed, you need to install them using your OS's package manager, usually: If you don't have luarocks installed, you need to install them using your OS's package manager, usually:
sudo apt-get install luarocks (Ubuntu / Debian) sudo apt-get install luarocks (Ubuntu / Debian)
On windows, a binary distribution can be downloaded from the LuaRocks homepage, http://luarocks.org/en/Download On windows, a binary distribution can be downloaded from the LuaRocks homepage, http://luarocks.org/en/Download
]]); ]])
print("Original error text: ", err); print("Original error text: ", err)
return nil; return nil
end end
-- We now know that LFS is present, get it normally: -- We now know that LFS is present, get it normally:
return require("lfs"); return require("lfs")
end end
local Arg1 = ...; local Arg1 = arg[1]
if ((Arg1 ~= nil) and (Arg1 ~= "")) then if ((Arg1 ~= nil) and (Arg1 ~= "")) then
-- Called with a plugin folder name, export only that one -- Called with a plugin folder name, export only that one
ProcessPluginFolder(Arg1) local isSuccess, msg = ProcessPluginFolder(Arg1)
if not(isSuccess) then
print(msg or "<unknown error>")
end
else else
-- Called without any arguments, process all subfolders: -- Called without any arguments, process all subfolders:
local lfs = LoadLFS(); local lfs = LoadLFS()
if (lfs == nil) then if (lfs == nil) then
-- LFS not loaded, error has already been printed, just bail out -- LFS not loaded, error has already been printed, just bail out
return; return
end end
print("Processing plugin subfolders:"); print("Processing plugin subfolders:")
for fnam in lfs.dir(".") do for fnam in lfs.dir(".") do
if ((fnam ~= ".") and (fnam ~= "..")) then if ((fnam ~= ".") and (fnam ~= "..")) then
local Attributes = lfs.attributes(fnam); local Attributes = lfs.attributes(fnam)
if (Attributes ~= nil) then if (Attributes ~= nil) then
if (Attributes.mode == "directory") then if (Attributes.mode == "directory") then
print(fnam); print(fnam)
ProcessPluginFolder(fnam); local isSuccess, msg = ProcessPluginFolder(fnam)
if not(isSuccess) then
print(" " .. (msg or "<unknown error>"))
end
end end
end end
end end
end end
end end
print("Done."); print("Done.")