aboutsummaryrefslogtreecommitdiff
path: root/nerv/init.lua
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2016-03-02 18:24:09 +0800
committerDeterminant <ted.sybil@gmail.com>2016-03-02 18:24:09 +0800
commitad704f2623cc9e0a5d702434bfdebc345465ca12 (patch)
tree898d0688e913efc3ff098ba51e5c1a5488f5771d /nerv/init.lua
parentd3abc6459a776ff7fa3777f4f561bc4f5d5e2075 (diff)
major changes in asr_trainer.lua; unified settings in `gconf`
Diffstat (limited to 'nerv/init.lua')
-rw-r--r--nerv/init.lua22
1 files changed, 12 insertions, 10 deletions
diff --git a/nerv/init.lua b/nerv/init.lua
index d72d8b8..a5b032c 100644
--- a/nerv/init.lua
+++ b/nerv/init.lua
@@ -182,15 +182,15 @@ end
-- value and description of the option.
--
-- An example of specification:
--- {{"aaa", "a", "bool", default = false, desc = "an option called aaa"},
--- {"bbb", "b", "bool", default = true, desc = "bbb is set to be true if --bbb=no does not present"},
+-- {{"aaa", "a", "boolean", default = false, desc = "an option called aaa"},
+-- {"bbb", "b", "boolean", default = true, desc = "bbb is set to be true if --bbb=no does not present"},
-- {"ccc", nil, "int", default = 0, desc = "ccc expects an integeral value"}}`
--
-- @return args, opts The non-option arguments and parsed options. `opts` is
-- again a list of tables, each of which corresponds to one table in parameter
-- `options`. The parsed value could be accessed by `opts["aaa"].val` (which is
-- `true` if "--aaa" or "-a" is specified).
-function nerv.parse_args(argv, options)
+function nerv.parse_args(argv, options, unordered)
local is_opt_exp = "^[-](.*)$"
local sim_opt_exp = "^[-]([a-z]+)$"
local opt_exp = "^[-][-]([^=]+)$"
@@ -198,6 +198,7 @@ function nerv.parse_args(argv, options)
local opts = {}
local sopts = {}
local args = {}
+ local arg_start = false
local function err()
nerv.error("invalid format of option specification")
end
@@ -215,7 +216,7 @@ function nerv.parse_args(argv, options)
val = v.default}
if opt_short ~= nil then
if type(opt_short) ~= "string" or #opt_short ~= 1 then err() end
- if opt_type ~= "bool" then
+ if opt_type ~= "boolean" then
nerv.error("only boolean option could have short form")
end
sopts[opt_short] = opt_meta
@@ -226,7 +227,7 @@ function nerv.parse_args(argv, options)
end
end
for _, token in ipairs(argv) do
- if token:match(is_opt_exp) then
+ if ((not arg_start) or unordered) and token:match(is_opt_exp) then
local k = token:match(sim_opt_exp)
if k then
for c in k:gmatch"." do
@@ -242,7 +243,7 @@ function nerv.parse_args(argv, options)
if opts[k] == nil then
nerv.error("invalid option %s", token)
end
- if opts[k].type ~= "bool" then
+ if opts[k].type ~= "boolean" then
nerv.error("invalid option --%s: " ..
"a %s value needs to be specified",
k, opts[k].type)
@@ -255,13 +256,13 @@ function nerv.parse_args(argv, options)
if opts[k] == nil then
nerv.error("invalid option %s", token)
end
- if opts[k].type == "bool" then
+ if opts[k].type == "boolean" then
if v == "yes" then
opts[k].val = true
elseif v == "no" then
opts[k].val = false
else
- nerv.error("bool value should be \"yes\" or \"no\"")
+ nerv.error("boolean value should be \"yes\" or \"no\"")
end
elseif opts[k].type == "int" then
local t = tonumber(v)
@@ -269,11 +270,11 @@ function nerv.parse_args(argv, options)
if t == nil or math.floor(t) ~= t then
nerv.error("int value is expected")
end
- elseif opts[k].type == "float" then
+ elseif opts[k].type == "number" then
local t = tonumber(v)
opts[k].val = t
if t == nil then
- nerv.error("float value is expected")
+ nerv.error("numeric value is expected")
end
elseif opts[k].type == "string" then
opts[k].val = v
@@ -287,6 +288,7 @@ function nerv.parse_args(argv, options)
end
else
table.insert(args, token)
+ arg_start = true
end
end
return args, opts