aboutsummaryrefslogtreecommitdiffstats
path: root/tools/migration/main.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2011-02-25 01:31:08 +0000
committerMatthew Wild <mwild1@gmail.com>2011-02-25 01:31:08 +0000
commitf3bd60789e8b2a5e63d8d21635e4ab1d0bf25cd8 (patch)
treeb913b67ac9ff2c9ca992fcf06af214eb9dea0910 /tools/migration/main.lua
parentf17b62707f5007b0e040261defd11d4c21dd309e (diff)
downloadprosody-f3bd60789e8b2a5e63d8d21635e4ab1d0bf25cd8.tar.gz
prosody-f3bd60789e8b2a5e63d8d21635e4ab1d0bf25cd8.zip
tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Diffstat (limited to 'tools/migration/main.lua')
-rw-r--r--tools/migration/main.lua40
1 files changed, 29 insertions, 11 deletions
diff --git a/tools/migration/main.lua b/tools/migration/main.lua
index a88da21e..772349bf 100644
--- a/tools/migration/main.lua
+++ b/tools/migration/main.lua
@@ -1,21 +1,39 @@
+-- Command-line parsing
+local options = {};
+local handled_opts = 0;
+for i = 1, #arg do
+ if arg[i]:sub(1,2) == "--" then
+ local opt, val = arg[i]:match("([%w-]+)=?(.*)");
+ if opt then
+ options[(opt:sub(3):gsub("%-", "_"))] = #val > 0 and val or true;
+ end
+ handled_opts = i;
+ else
+ break;
+ end
+end
+table.remove(arg, handled_opts);
-
-
+-- Load config file
local function loadfilein(file, env) return loadin and loadin(env, io.open(file):read("*a")) or setfenv(loadfile(file), env); end
config = {};
local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end });
-loadfilein("config.lua", config_env)();
+loadfilein(options.config or "config.lua", config_env)();
-package.path = "../../?.lua;"..package.path
-package.cpath = "../../?.dll;"..package.cpath
+if not package.loaded["util.json"] then
+ package.path = "../../?.lua;"..package.path
+ package.cpath = "../../?.dll;"..package.cpath
+end
+local from_store = arg[1] or "input";
+local to_store = arg[2] or "output";
-assert(config.input, "no input specified")
-assert(config.output, "no output specified")
-local itype = assert(config.input.type, "no input.type specified");
-local otype = assert(config.output.type, "no output.type specified");
-local reader = require(itype).reader(config.input);
-local writer = require(otype).writer(config.output);
+assert(config[from_store], "no input specified")
+assert(config[to_store], "no output specified")
+local itype = assert(config[from_store].type, "no type specified for "..from_store);
+local otype = assert(config[to_store].type, "no type specified for "..to_store);
+local reader = require(itype).reader(config[from_store]);
+local writer = require(otype).writer(config[to_store]);
local json = require "util.json";