diff -r 996f30d43a88 -r 5eda634ea15b main.lua --- a/main.lua Fri Dec 11 17:18:40 2015 +0000 +++ b/main.lua Fri Dec 11 17:19:30 2015 +0000 @@ -1,5 +1,40 @@ #!/usr/bin/env luajit +local property_rules = {}; + +local function apply_object_properties(class, name, object) + for _, rule in ipairs(property_rules) do + if (not(rule.class) or tostring(rule.class):lower() == tostring(class):lower()) + and (not(rule.name) or tostring(rule.name):lower() == tostring(name):lower()) then + for prop_key, prop_value in pairs(rule.properties) do + object[prop_key] = prop_value; + end + end + end +end + +function process_options() + local function get_value() + return (assert(table.remove(arg, 1), "unexpected end of command-line options")); + end + while arg[1] and arg[1]:sub(1,1) == "-" do + local opt = arg[1]; + if opt == "--" then + table.remove(arg, 1); + break; + end + table.remove(arg, 1); + if opt == "--port" or opt == "-p" then + local port = assert(tonumber(get_value()), "port number must be a number"); + table.insert(property_rules, { class = "client", properties = { connect_port = port } }); + elseif opt == "--host" or opt == "-h" then + local host = get_value(); + table.insert(property_rules, { class = "client", properties = { connect_host = host } }); + end + end + assert(#arg > 0, "No test script provided"); + assert(#arg < 2, "Too many parameters"); +end function read_script() io.input(arg[1]); @@ -18,6 +53,7 @@ local o = require("scansion.objects."..object.type); object.handler = o; object.script = script; + apply_object_properties(object.type, object.name, object); o._validate(object); c = c + 1; end @@ -41,6 +77,8 @@ end function main() + process_options(); + local ok, err = true; local script = initialize_script(parse_script(read_script()));