4 UCI Validation Layer - Command Line Utility
5 (c) 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6 (c) 2008 Steven Barth <steven@midlink.org>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
22 function getopt( arg, options )
23 options = options or ""
26 for k, v in ipairs(arg) do
27 if v:sub(1, 2) == "--" then
28 local x = v:find( "=", 1, true )
30 tab[ v:sub( 3, x-1 ) ] = v:sub( x+1 )
32 tab[ v:sub( 3 ) ] = true
34 elseif v:sub( 1, 1 ) == "-" then
40 if options:find( jopt, 1, true ) then
42 tab[ jopt ] = v:sub( y+1 )
45 tab[ jopt ] = arg[ k + 1 ]
60 local options, arguments = getopt( arg )
62 if #arguments == 0 or options.help then
65 uvl - UCI Validation Layer
67 (c) 2008 Jo-Philipp Wich, Steven Barth
71 uvl [--silent] [--schemedir=DIR]
72 [--no-strict-sections] [--no-strict-options] [--no-strict-validators]
73 [--no-strict-lists] config[.section[.option]]
77 Display this help message.
80 Don't produce any output.
83 Use DIR as scheme directory.
86 Don't treat sections found in config but not in scheme as error.
89 Don't treat options found in config but not in scheme as error.
91 --no-strict-validators
92 Don't invalidate config if an external validator fails.
95 Don't invalidate lists that are stored options.
99 luci.uvl.STRICT_UNKNOWN_SECTIONS =
100 ( options['no-strict-sections'] and false or true )
101 luci.uvl.STRICT_UNKNOWN_OPTIONS =
102 ( options['no-strict-options'] and false or true )
103 luci.uvl.STRICT_EXTERNAL_VALIDATORS =
104 ( options['no-strict-validators'] and false or true )
105 luci.uvl.STRICT_LIST_TYPE =
106 ( options['no-strict-lists'] and false or true )
108 local uvl = luci.uvl.UVL(
109 type(options.schemedir) == "string" and options.schemedir or nil
112 local cso = luci.util.split( arguments[1], "." )
113 local ok, err = uvl:validate( unpack(cso) )
116 if not options.silent then
117 print( string.format(
118 '%s "%s" validates fine!',
119 ( #cso == 1 and "Config" or
120 ( #cso == 2 and "Section" or "Option" ) ),
121 table.concat(cso, ".")
126 if not options.silent then print( err ) end