Skip to content

Commit 389d5e0

Browse files
committed
Limit number of properties that can be set as call arguments
1 parent d88c84b commit 389d5e0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/argparse.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local function deep_update(t1, t2)
1111
end
1212

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

5557
for i, property in ipairs(properties) do
56-
if i > nargs then
58+
if i > nargs or i > properties.args then
5759
break
5860
end
5961

@@ -188,6 +190,7 @@ local Parser = new_class({
188190
_require_command = true,
189191
_handle_options = true
190192
}, {
193+
args = 3,
191194
typechecked("name", "string"),
192195
typechecked("description", "string"),
193196
typechecked("epilog", "string"),
@@ -201,6 +204,7 @@ local Parser = new_class({
201204
local Command = new_class({
202205
_aliases = {}
203206
}, {
207+
args = 3,
204208
multiname,
205209
typechecked("description", "string"),
206210
typechecked("epilog", "string"),
@@ -221,6 +225,7 @@ local Argument = new_class({
221225
_defmode = "unused",
222226
_show_default = true
223227
}, {
228+
args = 5,
224229
typechecked("name", "string"),
225230
typechecked("description", "string"),
226231
typechecked("default", "string"),
@@ -237,6 +242,7 @@ local Option = new_class({
237242
_mincount = 0,
238243
_overwrite = true
239244
}, {
245+
args = 6,
240246
multiname,
241247
typechecked("description", "string"),
242248
typechecked("default", "string"),

0 commit comments

Comments
 (0)