From db90cb44d7cde5457f7f55e8c93a0718811ef149 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 24 Mar 2015 00:59:47 -0300 Subject: Really test for missing parameters. If we have a test for that, then it must have caused trouble in the past. --- src/luarocks/util.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 2d57f9dc..366a7ace 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -63,6 +63,12 @@ function util.matchquote(s) return (s:gsub("[?%-+*%[%].%%()$^]","%%%1")) end +--- List of supported arguments. +-- Arguments that take no parameters are marked with the boolean true. +-- Arguments that take a parameter are marked with a descriptive string. +-- Arguments that may take an empty string are described in quotes, +-- (as in the value for --detailed=""). +-- For all other string values, it means the parameter is mandatory. local supported_flags = { ["all"] = true, ["api-key"] = "", @@ -80,7 +86,7 @@ local supported_flags = { ["from"] = "", ["help"] = true, ["home"] = true, - ["homepage"] = "", + ["homepage"] = "\"\"", ["keep"] = true, ["lib"] = "", ["license"] = "\"\"", @@ -141,6 +147,9 @@ function util.parse_flags(...) if val then local vartype = supported_flags[var] if type(vartype) == "string" then + if val == "" and vartype:sub(1,1) ~= '"' then + return { ERROR = "Invalid argument: parameter to flag --"..var.."="..vartype.." cannot be empty." } + end flags[var] = val else if vartype then @@ -161,6 +170,9 @@ function util.parse_flags(...) if val:match("^%-%-.*") then return { ERROR = "Invalid argument: flag --"..var.."="..vartype.." expects a parameter (if you really want to pass "..val.." as an argument to --"..var..", use --"..var.."="..val..")." } else + if val == "" and vartype:sub(1,1) ~= '"' then + return { ERROR = "Invalid argument: parameter to flag --"..var.."="..vartype.." cannot be empty." } + end flags[var] = val end elseif vartype == true then -- cgit v1.2.3-55-g6feb