Skip to content

Commit

Permalink
Limit number of properties that can be set as call arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed Jun 20, 2015
1 parent d88c84b commit 389d5e0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/argparse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local function deep_update(t1, t2)
end

-- A property is a tuple {name, callback}.
-- properties.args is number of properties that can be set as arguments
-- when calling an object.
local function new_class(prototype, properties, parent)
-- Class is the metatable of its instances.
local class = {}
Expand Down Expand Up @@ -53,7 +55,7 @@ local function new_class(prototype, properties, parent)
local nargs = select("#", ...)

for i, property in ipairs(properties) do
if i > nargs then
if i > nargs or i > properties.args then
break
end

Expand Down Expand Up @@ -188,6 +190,7 @@ local Parser = new_class({
_require_command = true,
_handle_options = true
}, {
args = 3,
typechecked("name", "string"),
typechecked("description", "string"),
typechecked("epilog", "string"),
Expand All @@ -201,6 +204,7 @@ local Parser = new_class({
local Command = new_class({
_aliases = {}
}, {
args = 3,
multiname,
typechecked("description", "string"),
typechecked("epilog", "string"),
Expand All @@ -221,6 +225,7 @@ local Argument = new_class({
_defmode = "unused",
_show_default = true
}, {
args = 5,
typechecked("name", "string"),
typechecked("description", "string"),
typechecked("default", "string"),
Expand All @@ -237,6 +242,7 @@ local Option = new_class({
_mincount = 0,
_overwrite = true
}, {
args = 6,
multiname,
typechecked("description", "string"),
typechecked("default", "string"),
Expand Down

0 comments on commit 389d5e0

Please sign in to comment.