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
14 $Id: uvl.lua 2873 2008-08-17 21:43:56Z jow $
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
66 $Id: uvl.lua 2873 2008-08-17 21:43:56Z jow $
67 (c) 2008 Jo-Philipp Wich, Steven Barth
71 uvl [--silent] [--schemedir=DIR]
72 [--no-strict-sections] [--no-strict-options]
73 [--no-strict-validators] 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.
96 luci.uvl.STRICT_UNKNOWN_SECTIONS =
97 ( options['no-strict-sections'] and false or true )
98 luci.uvl.STRICT_UNKNOWN_OPTIONS =
99 ( options['no-strict-options'] and false or true )
100 luci.uvl.STRICT_EXTERNAL_VALIDATORS =
101 ( options['no-strict-validators'] and false or true )
103 local uvl = luci.uvl.UVL(
104 type(options.schemedir) == "string" and options.schemedir or nil
107 local cso = luci.util.split( arguments[1], "." )
108 local ok, err = uvl:validate( unpack(cso) )
111 if not options.silent then
112 print( string.format(
113 '%s "%s" validates fine!',
114 ( #cso == 1 and "Config" or
115 ( #cso == 2 and "Section" or "Option" ) ),
116 table.concat(cso, ".")
121 if not options.silent then print( err ) end