3 UCI Validation Layer - Command Line Utility
4 (c) 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5 (c) 2008 Steven Barth <steven@midlink.org>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 $Id: uvl.lua 2873 2008-08-17 21:43:56Z jow $
21 function getopt( arg, options )
22 options = options or ""
25 for k, v in ipairs(arg) do
26 if v:sub(1, 2) == "--" then
27 local x = v:find( "=", 1, true )
29 tab[ v:sub( 3, x-1 ) ] = v:sub( x+1 )
31 tab[ v:sub( 3 ) ] = true
33 elseif v:sub( 1, 1 ) == "-" then
39 if options:find( jopt, 1, true ) then
41 tab[ jopt ] = v:sub( y+1 )
44 tab[ jopt ] = arg[ k + 1 ]
59 local options, arguments = getopt( arg )
61 if #arguments == 0 or options.help then
63 uvl - UCI Validation Layer
64 $Id: uvl.lua 2873 2008-08-17 21:43:56Z jow $
65 (c) 2008 Jo-Philipp Wich, Steven Barth
69 uvl [--silent] [--no-strict-sections] [--no-strict-options]
70 [--no-strict-validators] config[.section[.option]]
74 Display this help message.
77 Don't produce any output.
80 Don't treat sections found in config but not in scheme as error.
83 Don't treat options found in config but not in scheme as error.
85 --no-strict-validators
86 Don't invalidate config if an external validators fails.
91 luci.uvl.STRICT_UNKNOWN_SECTIONS =
92 ( options['no-strict-sections'] and false or true )
93 luci.uvl.STRICT_UNKNOWN_OPTIONS =
94 ( options['no-strict-options'] and false or true )
95 luci.uvl.STRICT_EXTERNAL_VALIDATORS =
96 ( options['no-strict-validators'] and false or true )
98 local uvl = luci.uvl.UVL( options['schemedir'] )
99 local cso = luci.util.split( arguments[1], "." )
100 local ok, err = uvl:validate( unpack(cso) )
103 if not options.silent then
104 print( string.format(
105 '%s "%s.%s.%s" validates fine!',
106 ( #cso == 1 and "Config" or
107 ( #cso == 2 and "Section" or "Option" ) ),
108 cso[1], cso[2], cso[3]
113 if not options.silent then print( err ) end