aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-03-24 00:59:47 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-03-24 00:59:47 -0300
commitdb90cb44d7cde5457f7f55e8c93a0718811ef149 (patch)
tree54426953428a07870e5131733f86b06c75b66022 /src
parenta027595f718c6b05a8fbd4feae1605bff3fed5b9 (diff)
downloadluarocks-db90cb44d7cde5457f7f55e8c93a0718811ef149.tar.gz
luarocks-db90cb44d7cde5457f7f55e8c93a0718811ef149.tar.bz2
luarocks-db90cb44d7cde5457f7f55e8c93a0718811ef149.zip
Really test for missing parameters.
If we have a test for that, then it must have caused trouble in the past.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/util.lua14
1 files changed, 13 insertions, 1 deletions
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)
63 return (s:gsub("[?%-+*%[%].%%()$^]","%%%1")) 63 return (s:gsub("[?%-+*%[%].%%()$^]","%%%1"))
64end 64end
65 65
66--- List of supported arguments.
67-- Arguments that take no parameters are marked with the boolean true.
68-- Arguments that take a parameter are marked with a descriptive string.
69-- Arguments that may take an empty string are described in quotes,
70-- (as in the value for --detailed="<text>").
71-- For all other string values, it means the parameter is mandatory.
66local supported_flags = { 72local supported_flags = {
67 ["all"] = true, 73 ["all"] = true,
68 ["api-key"] = "<key>", 74 ["api-key"] = "<key>",
@@ -80,7 +86,7 @@ local supported_flags = {
80 ["from"] = "<server>", 86 ["from"] = "<server>",
81 ["help"] = true, 87 ["help"] = true,
82 ["home"] = true, 88 ["home"] = true,
83 ["homepage"] = "<url>", 89 ["homepage"] = "\"<url>\"",
84 ["keep"] = true, 90 ["keep"] = true,
85 ["lib"] = "<library>", 91 ["lib"] = "<library>",
86 ["license"] = "\"<text>\"", 92 ["license"] = "\"<text>\"",
@@ -141,6 +147,9 @@ function util.parse_flags(...)
141 if val then 147 if val then
142 local vartype = supported_flags[var] 148 local vartype = supported_flags[var]
143 if type(vartype) == "string" then 149 if type(vartype) == "string" then
150 if val == "" and vartype:sub(1,1) ~= '"' then
151 return { ERROR = "Invalid argument: parameter to flag --"..var.."="..vartype.." cannot be empty." }
152 end
144 flags[var] = val 153 flags[var] = val
145 else 154 else
146 if vartype then 155 if vartype then
@@ -161,6 +170,9 @@ function util.parse_flags(...)
161 if val:match("^%-%-.*") then 170 if val:match("^%-%-.*") then
162 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..")." } 171 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..")." }
163 else 172 else
173 if val == "" and vartype:sub(1,1) ~= '"' then
174 return { ERROR = "Invalid argument: parameter to flag --"..var.."="..vartype.." cannot be empty." }
175 end
164 flags[var] = val 176 flags[var] = val
165 end 177 end
166 elseif vartype == true then 178 elseif vartype == true then