elua: match help categories in a case insensitive way, and add them to lualian

This commit is contained in:
Daniel Kolesa 2014-04-30 10:32:50 +01:00 committed by Daniel Kolesa
parent e293536915
commit a94c216442
2 changed files with 12 additions and 5 deletions

View File

@ -18,15 +18,20 @@ getopt.parse {
usage = "Usage: %prog [OPTIONS] file1.eo file2.eo ... fileN.eo", usage = "Usage: %prog [OPTIONS] file1.eo file2.eo ... fileN.eo",
args = arg, args = arg,
descs = { descs = {
{ "h", "help", false, help = "Show this message.", { category = "General" },
callback = function(d, parser)
getopt.help(parser, io.stdout) { "h", "help", nil, help = "Show this message.", metavar = "CATEGORY",
callback = function(d, parser, v)
getopt.help(parser, v, io.stdout)
quit = true quit = true
end end
}, },
{ "v", "verbose", false, help = "Be verbose.", { "v", "verbose", false, help = "Be verbose.",
callback = function() printv = print end callback = function() printv = print end
}, },
{ category = "Generator" },
{ "I", "include", true, help = "Include a directory.", metavar = "DIR", { "I", "include", true, help = "Include a directory.", metavar = "DIR",
callback = function(d, p, v) callback = function(d, p, v)
include_dirs[#include_dirs + 1] = v include_dirs[#include_dirs + 1] = v

View File

@ -169,8 +169,10 @@ local help = function(parser, f, category)
lln = math.max(lln, #ln) lln = math.max(lln, #ln)
lns[#lns + 1] = { ln, desc.help } lns[#lns + 1] = { ln, desc.help }
elseif desc.category then elseif desc.category then
iscat = (not category) or (desc.alias == category) local lcat = category and category:lower() or nil
or (desc.category == category) local alias = desc.alias and desc.alias:lower() or nil
iscat = (not category) or (alias == lcat)
or (desc.category:lower() == lcat)
if iscat then if iscat then
wascat = true wascat = true
lns[#lns + 1] = { false, desc.category } lns[#lns + 1] = { false, desc.category }