#!/usr/bin/luaweb
json = require("json")
omg = require("omg")

--[[ This function copy a table recursive
]]
function copyTableIntoOther(out,data)
   for k,v in pairs(data) do
      if (type(v) == "table") then
         if out[k]==nil or type(out[k])~="table" then
            out[k]={}
            end
         copyTableIntoOther(out[k],v)
        else
           out[k] = v
        end
    end
end

function getConfigSetsFile(fileName)
    local f
    if io ~= nil and io.open ~= nil then
       f = io.open(fileName,"r")
        if f ~= nil then
           local content = f:read("*all")
            if content ~= nil then
               local tmpConfig = json.decode(content)
               if tmpConfig~=nil ~= nil then
                  copyTableIntoOther(config,tmpConfig)
                end 
            end
        end
    end
end

helpString=omg.getHelpString(arg[0],"show config parameter used by sipisdn\n")
helpString=helpString .. "\t--list\tgives a list parameter names\n"
function omg.getHelpString(name,desc)
 return helpString
end

myOptions=omg.splitCommandlineString(arg)
 
config={}

getConfigSetsFile("/usr/fb/configpars.json")


if config ~= nil then

   if myOptions.list~=nil then
      for k,v in pairs(config) do
         print(k)
      end
   else
      omg.runScript(config,arg,"show config script settings\n")
   end
end




