
-- main.lua
package.path = "/usr/share/kses/templating/?.lua;"..package.path
--package.path = "/home/default/luatests/?.lua;"..package.path
package.path = "/srv/http/?.lua;"..package.path


--Where the project starts from.


local lapp = require("pl.lapp")
local pretty = require("pl.pretty")

--local pretty = require("pl.pretty")
local parser = require("configParser")

local args = lapp [[
Runs the config engine daemon.
-o,--option (default nil)  use s to denote saving a template or l for loading
-f,--filename (default "latest.template") the file name of the template
-t,--tierload (default "d") use d to denote loading device tier or p for port tier
-d,--templatedir (default "./templates/") the template directory
]]



if args.option == "l" then


  local loader = require("loader")

  if args.tierload == "p" then

    local loaded = loader:loadConfigToFile(args.templatedir,args.filename,"RsmD")
  elseif args.tierload == "d" then

    local loaded = loader:loadSiteConfig(args.templatedir,args.filename)
  else
    print("no tier option given")
  end

elseif args.option == "s" then
  local saver = require("saver")

  local testret = saver:saveConfigToFile()

  --print("Using frikkie")

  parser.write(args.templatedir..args.filename,"xml",testret)

else
  print("Incorrect option given. must be either 's' or 'l'")
  print(pretty.write(args))
  return
end
