* luci/libs/lua: process option dependencies first, allows mixing of required flags with dependencies
This commit is contained in:
parent
e0e58e842d
commit
4219ec1754
1 changed files with 26 additions and 18 deletions
|
@ -292,6 +292,21 @@ function UVL._validate_option( self, option, nodeps )
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif option:scheme() then
|
elseif option:scheme() then
|
||||||
|
if not nodeps then
|
||||||
|
local ok, err = dependencies.check( self, option )
|
||||||
|
if not ok then
|
||||||
|
-- XXX: maybe this needs to be more specific
|
||||||
|
if not err:is(ERR.ERR_DEP_NOTEQUAL) and
|
||||||
|
not err:is(ERR.ERR_DEP_NOVALUE)
|
||||||
|
then
|
||||||
|
option:error(err)
|
||||||
|
return false, option:errors()
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if option:scheme('required') and not option:value() then
|
if option:scheme('required') and not option:value() then
|
||||||
return false, option:error(ERR.OPT_REQUIRED(option))
|
return false, option:error(ERR.OPT_REQUIRED(option))
|
||||||
|
|
||||||
|
@ -363,13 +378,6 @@ function UVL._validate_option( self, option, nodeps )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not nodeps then
|
|
||||||
local ok, err = dependencies.check( self, option )
|
|
||||||
if not ok then
|
|
||||||
option:error(err)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = validation.check( self, option )
|
local ok, err = validation.check( self, option )
|
||||||
|
@ -554,8 +562,7 @@ function UVL._parse_section(self, scheme, k, v)
|
||||||
s.named = s.named or false
|
s.named = s.named or false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Step 2: get all variables
|
||||||
-- Step 2: get all variables
|
|
||||||
function UVL._parse_var(self, scheme, k, v)
|
function UVL._parse_var(self, scheme, k, v)
|
||||||
local ok, err = _req( TYPE_OPTION, k, v, { "name", "section" } )
|
local ok, err = _req( TYPE_OPTION, k, v, { "name", "section" } )
|
||||||
if err then error(scheme:error(err)) end
|
if err then error(scheme:error(err)) end
|
||||||
|
@ -611,8 +618,9 @@ function UVL._parse_var(self, scheme, k, v)
|
||||||
t.valueof = type(v2) == "table" and v2 or {v2}
|
t.valueof = type(v2) == "table" and v2 or {v2}
|
||||||
elseif k == "required" then
|
elseif k == "required" then
|
||||||
t[k] = _bool(v2)
|
t[k] = _bool(v2)
|
||||||
elseif k == "minlength" or k == "maxlength"
|
elseif k == "minlength" or k == "maxlength" or
|
||||||
or k == "minimum" or k == "maximum" then
|
k == "minimum" or k == "maximum"
|
||||||
|
then
|
||||||
t[k] = tonumber(v2)
|
t[k] = tonumber(v2)
|
||||||
else
|
else
|
||||||
t[k] = t[k] or v2
|
t[k] = t[k] or v2
|
||||||
|
|
Loading…
Reference in a new issue