* luci/libs/uvl:
- implement aliasing in luci.uvl.read_scheme() - fixed wrong enum definition in reference scheme - fixed boolean() datatype validator to actually accept "true" and "false" literals - extend uvl cli to validate schemes against the reference scheme (incomplete)
This commit is contained in:
parent
34ab619ee3
commit
19e22598fd
4 changed files with 38 additions and 14 deletions
|
@ -351,7 +351,8 @@ end
|
||||||
-- This is normally done on demand, so you don't have to call this function
|
-- This is normally done on demand, so you don't have to call this function
|
||||||
-- by yourself.
|
-- by yourself.
|
||||||
-- @param scheme Name of the scheme to parse
|
-- @param scheme Name of the scheme to parse
|
||||||
function UVL.read_scheme( self, scheme )
|
-- @param alias Create an alias for the loaded scheme
|
||||||
|
function UVL.read_scheme( self, scheme, alias )
|
||||||
|
|
||||||
local so = luci.uvl.scheme( self, scheme )
|
local so = luci.uvl.scheme( self, scheme )
|
||||||
|
|
||||||
|
@ -375,7 +376,9 @@ function UVL.read_scheme( self, scheme )
|
||||||
table.insert( schemes, sd )
|
table.insert( schemes, sd )
|
||||||
end
|
end
|
||||||
|
|
||||||
return self:_read_scheme_parts( so, schemes )
|
local ok, err = self:_read_scheme_parts( so, schemes )
|
||||||
|
if ok and alias then self.packages[alias] = self.packages[scheme] end
|
||||||
|
return ok, err
|
||||||
else
|
else
|
||||||
return false, so:error(ERR.SME_FIND(so, self.schemedir))
|
return false, so:error(ERR.SME_FIND(so, self.schemedir))
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,9 +22,9 @@ require("luci.util")
|
||||||
|
|
||||||
|
|
||||||
function boolean( val )
|
function boolean( val )
|
||||||
if val == "1" or val == "yes" or val == "on" then
|
if val == "1" or val == "yes" or val == "on" or val == "true" then
|
||||||
return true
|
return true
|
||||||
elseif val == "0" or val == "no" or val == "off" then
|
elseif val == "0" or val == "no" or val == "off" or val == "false" then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -305,8 +305,8 @@ config section
|
||||||
|
|
||||||
# Enum value (schema.@enum.value)
|
# Enum value (schema.@enum.value)
|
||||||
config variable
|
config variable
|
||||||
option name 'name'
|
option name 'value'
|
||||||
option title 'Name of the defined variable'
|
option title 'Value of the defined enum value'
|
||||||
option section 'schema.enum'
|
option section 'schema.enum'
|
||||||
option type 'variable'
|
option type 'variable'
|
||||||
option datatype 'string'
|
option datatype 'string'
|
||||||
|
|
|
@ -149,9 +149,9 @@ $Id$
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
uvl --help
|
uvl --help
|
||||||
uvl [--silent] [--schemedir=DIR]
|
uvl [--silent] [--schemedir=DIR] [--configdir=DIR] [--no-strict-sections] \
|
||||||
[--no-strict-sections] [--no-strict-options] [--no-strict-validators]
|
[--no-strict-options] [--no-strict-validators] [--no-strict-lists] \
|
||||||
[--no-strict-lists] {verify|genspec} config[.section[.option]]
|
{verify|verify-scheme|genspec} config[.section[.option]]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--help
|
--help
|
||||||
|
@ -163,6 +163,9 @@ Options:
|
||||||
--schemedir=DIR
|
--schemedir=DIR
|
||||||
Use DIR as scheme directory.
|
Use DIR as scheme directory.
|
||||||
|
|
||||||
|
--configdir=DIR
|
||||||
|
Use DIR as config directory.
|
||||||
|
|
||||||
--no-strict-sections
|
--no-strict-sections
|
||||||
Don't treat sections found in config but not in scheme as error.
|
Don't treat sections found in config but not in scheme as error.
|
||||||
|
|
||||||
|
@ -179,11 +182,14 @@ Actions:
|
||||||
verify
|
verify
|
||||||
Validate given configuration, section or option.
|
Validate given configuration, section or option.
|
||||||
|
|
||||||
|
verify-scheme
|
||||||
|
Validate given scheme against the reference meta scheme.
|
||||||
|
|
||||||
genspec
|
genspec
|
||||||
Generate a scheme skeleton from given configuration.
|
Generate a scheme skeleton from given configuration.
|
||||||
]=])
|
]=])
|
||||||
os.exit(255)
|
os.exit(255)
|
||||||
elseif arguments[1] == "verify" then
|
elseif arguments[1] == "verify" or arguments[1] == "verify-scheme" then
|
||||||
luci.uvl.STRICT_UNKNOWN_SECTIONS =
|
luci.uvl.STRICT_UNKNOWN_SECTIONS =
|
||||||
( not options['no-strict-sections'] and true or false )
|
( not options['no-strict-sections'] and true or false )
|
||||||
luci.uvl.STRICT_UNKNOWN_OPTIONS =
|
luci.uvl.STRICT_UNKNOWN_OPTIONS =
|
||||||
|
@ -194,18 +200,33 @@ elseif arguments[1] == "verify" then
|
||||||
( not options['no-strict-lists'] and true or false )
|
( not options['no-strict-lists'] and true or false )
|
||||||
|
|
||||||
local uvl = luci.uvl.UVL(
|
local uvl = luci.uvl.UVL(
|
||||||
type(options.schemedir) == "string" and options.schemedir or nil
|
type(options.schemedir) == "string" and options.schemedir
|
||||||
)
|
)
|
||||||
|
|
||||||
local cso = luci.util.split( arguments[2], "." )
|
local cso = luci.util.split( arguments[2], "." )
|
||||||
local ok, err = uvl:validate( unpack(cso) )
|
local ok, err
|
||||||
|
|
||||||
|
if arguments[1] == "verify-scheme" then
|
||||||
|
uvl:read_scheme( 'schema', cso[1] )
|
||||||
|
|
||||||
|
local uci = uvl.uci.cursor(
|
||||||
|
type(options.configdir) == "string"
|
||||||
|
and options.configdir or uvl.schemedir .. '/default'
|
||||||
|
)
|
||||||
|
|
||||||
|
ok, err = uvl:validate_config( cso[1], uci:get_all(cso[1]) )
|
||||||
|
if err then err.code = luci.uvl.errors.ERR_SCHEME end
|
||||||
|
else
|
||||||
|
ok, err = uvl:validate( unpack(cso) )
|
||||||
|
end
|
||||||
|
|
||||||
if ok then
|
if ok then
|
||||||
if not options.silent then
|
if not options.silent then
|
||||||
print( string.format(
|
print( string.format(
|
||||||
'%s "%s" validates fine!',
|
'%s "%s" validates fine!',
|
||||||
( #cso == 1 and "Config" or
|
( arguments[1] == "verify-scheme" and "Scheme" or
|
||||||
( #cso == 2 and "Section" or "Option" ) ),
|
( #cso == 1 and "Config" or
|
||||||
|
( #cso == 2 and "Section" or "Option" ) ) ),
|
||||||
table.concat(cso, ".")
|
table.concat(cso, ".")
|
||||||
) )
|
) )
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue