options[name] = {
type = "option",
documentation = doc or "", name = name,
- proc=func,
- default=default or true,
+ proc = func,
+ default = default,
argumentname=argname or "ARGUMENT"
}
end
if options[opt] then
local proc = options[opt].proc
if options[opt].type == "option" then
+ local optarg
+
if i == #args then
- return false,
- err.new("argument missing for option: %s", opt)
+ if options[opt].default == nil then
+ return false,
+ err.new("argument missing for option: %s",
+ opt)
+ else
+ optarg = options[opt].default
+ end
+ else
+ optarg = args[i + 1]
end
+
if proc then
- opts[opt] = proc(args[i + 1])
+ opts[opt] = proc(optarg)
else
- opts[opt] = args[i + 1]
+ opts[opt] = optarg
end
i = i + 1
else