2 local cbi = require "luci.cbi"
3 local i18n = require "luci.i18n"
4 local util = require "luci.util"
7 util.perror("Usage %s path/to/cbi/model.lua [i18nfilename]" % arg[0])
11 i18n.load("default", "en")
12 i18n.load("admin-core", "en")
13 i18n.load("wifi", "en")
16 i18n.load(arg[2], "en")
19 local map = cbi.load(arg[1])[1]
22 print ("package "..map.config)
23 print ("\nconfig package")
25 if #map.title > 0 then
26 print (" option title '%s'" % util.striptags(map.title))
29 if #map.description > 0 then
30 print (" option description '%s'" % util.striptags(map.description))
33 for i, sec in pairs(map.children) do if util.instanceof(sec, cbi.TypedSection) then
34 print ("\nconfig section")
35 print (" option name '%s'" % sec.sectiontype)
36 print (" option package '%s'" % map.config)
38 if #sec.title > 0 then
39 print (" option title '%s'" % util.striptags(sec.title))
42 if #sec.description > 0 then
43 print (" option description '%s'" % util.striptags(sec.description))
46 if not sec.addremove then
47 print (" option unique true")
48 print (" option required true")
51 if not sec.anonymous then
52 print (" option named true")
56 print (" option dynamic true")
59 for j, opt in ipairs(sec.children) do
60 if opt.option:sub(1,1) ~= "_" or util.instanceof(opt, cbi.Value) then
61 print ("\nconfig variable")
62 print (" option name '%s'" % opt.option)
63 print (" option section '%s.%s'" % {map.config, sec.sectiontype})
64 if #opt.title > 0 then
65 print (" option title '%s'" % util.striptags(opt.title))
68 if #opt.description > 0 then
69 print (" option description '%s'" % util.striptags(opt.description))
72 if not opt.rmempty and not opt.optional then
73 print (" option required true")
76 if util.instanceof(opt, cbi.Flag) then
77 print (" option datatype boolean")
78 elseif util.instanceof(opt, cbi.DynamicList) then
79 print (" option type list")
80 elseif util.instanceof(opt, cbi.ListValue) then
81 print (" option type enum")
82 util.perror("*** Warning: Please verify '%s.%s.%s' ***" %
83 {map.config, sec.sectiontype, opt.option} )
86 for i, dep in ipairs(opt.deps) do
87 if not dep.add or dep.add == "" then
89 for k, v in pairs(dep.deps) do
90 depstring = (depstring and depstring .. "," or "") .. "%s=%s" % {k, v}
92 print (" list depends '%s'" % depstring)
94 util.perror("*** Warning: Unable to decode dependency '%s' in '%s.%s.%s[%s]' ***" %
95 {util.serialize_data(dep.deps), map.config, sec.sectiontype, opt.option, dep.add})
99 if util.instanceof(opt, cbi.ListValue) then
100 for k, key in ipairs(opt.keylist) do
101 print ("\nconfig enum")
102 print (" option variable '%s.%s.%s'" % {map.config, sec.sectiontype, opt.option})
103 print (" option value '%s'" % key)
104 if opt.vallist[k] and opt.vallist[k] ~= opt.keylist[k] then
105 print (" option title '%s'" % util.striptags(opt.vallist[k]))