diff --git a/src/bin/elua/lualian.lua b/src/bin/elua/lualian.lua index 0fd1e97405..6b2e4a3c2d 100644 --- a/src/bin/elua/lualian.lua +++ b/src/bin/elua/lualian.lua @@ -17,8 +17,8 @@ local opts, args, arg_parser = getopt.parse { usage = "Usage: %prog [OPTIONS] file1.eo file2.eo ... fileN.eo", args = arg, descs = { { "h", "help", false, help = "Show this message.", - callback = function(d, p) - getopt.help_cb(io.stdout)(d, p) + callback = function(d, parser) + getopt.help(parser, io.stdout) quit = true end }, @@ -45,15 +45,13 @@ local opts, args, arg_parser = getopt.parse { output_files[#output_files + 1] = v end } - } + }, error_cb = function(parser, msg) + io.stderr:write(msg, "\n") + getopt.help(parser, io.stderr) + quit = true + end } -if not opts then - io.stderr:write(args, "\n") - getopt.help(arg_parser, io.stderr) - return -end - if quit then return end if not libname then diff --git a/src/bin/elua/modules/getopt.lua b/src/bin/elua/modules/getopt.lua index f90b0e70d0..8ec42170a6 100644 --- a/src/bin/elua/modules/getopt.lua +++ b/src/bin/elua/modules/getopt.lua @@ -2,17 +2,17 @@ local M = {} +local prefixes = { "-", "--" } + local get_desc = function(opt, j, descs) for i, v in ipairs(descs) do if v[j] == opt then return v end end - error("option --" .. opt .. " not recognized", 4) + error("option " .. prefixes[j] .. opt .. " not recognized", 4) end -local prefixes = { "-", "--" } - local is_arg = function(opt, j, descs) if opt == "--" then return true end for i, v in ipairs(descs) do @@ -102,6 +102,9 @@ end M.parse = function(parser) local ret, opts, args = pcall(getopt_u, parser) if not ret then + if parser.error_cb then + parser:error_cb(opts) + end return nil, opts end return opts, args, parser