mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Merge pull request #2 from Alloyed/add-handle-options-property
Add handle_options property to Parser
This commit is contained in:
@@ -125,6 +125,17 @@ describe("tests related to options", function()
|
|||||||
assert.same({input = "foo", exclude = {}}, args)
|
assert.same({input = "foo", exclude = {}}, args)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("does not interpret options if disabled", function()
|
||||||
|
local parser = Parser()
|
||||||
|
parser:handle_options(false)
|
||||||
|
parser:argument "input"
|
||||||
|
:args "*"
|
||||||
|
parser:option "-f" "--foo"
|
||||||
|
:args "*"
|
||||||
|
local args = parser:parse{"bar", "-f", "--foo" , "bar"}
|
||||||
|
assert.same({input = {"bar", "-f", "--foo" , "bar"}}, args)
|
||||||
|
end)
|
||||||
|
|
||||||
describe("Special chars set", function()
|
describe("Special chars set", function()
|
||||||
it("handles windows-style options", function()
|
it("handles windows-style options", function()
|
||||||
local parser = Parser()
|
local parser = Parser()
|
||||||
|
@@ -183,7 +183,8 @@ local Parser = new_class({
|
|||||||
_options = {},
|
_options = {},
|
||||||
_commands = {},
|
_commands = {},
|
||||||
_mutexes = {},
|
_mutexes = {},
|
||||||
_require_command = true
|
_require_command = true,
|
||||||
|
_handle_options = true
|
||||||
}, {
|
}, {
|
||||||
typechecked("name", "string"),
|
typechecked("name", "string"),
|
||||||
typechecked("description", "string"),
|
typechecked("description", "string"),
|
||||||
@@ -191,6 +192,7 @@ local Parser = new_class({
|
|||||||
typechecked("usage", "string"),
|
typechecked("usage", "string"),
|
||||||
typechecked("help", "string"),
|
typechecked("help", "string"),
|
||||||
typechecked("require_command", "boolean"),
|
typechecked("require_command", "boolean"),
|
||||||
|
typechecked("handle_options", "boolean"),
|
||||||
add_help
|
add_help
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -204,6 +206,7 @@ local Command = new_class({
|
|||||||
typechecked("usage", "string"),
|
typechecked("usage", "string"),
|
||||||
typechecked("help", "string"),
|
typechecked("help", "string"),
|
||||||
typechecked("require_command", "boolean"),
|
typechecked("require_command", "boolean"),
|
||||||
|
typechecked("handle_options", "boolean"),
|
||||||
typechecked("action", "function"),
|
typechecked("action", "function"),
|
||||||
add_help
|
add_help
|
||||||
}, Parser)
|
}, Parser)
|
||||||
@@ -673,6 +676,7 @@ function Parser:_parse(args, errhandler)
|
|||||||
local cur_arg_i = 1
|
local cur_arg_i = 1
|
||||||
local cur_arg
|
local cur_arg
|
||||||
local targets = {}
|
local targets = {}
|
||||||
|
local handle_options = true
|
||||||
|
|
||||||
local function error_(fmt, ...)
|
local function error_(fmt, ...)
|
||||||
return errhandler(parser, fmt:format(...))
|
return errhandler(parser, fmt:format(...))
|
||||||
@@ -824,6 +828,7 @@ function Parser:_parse(args, errhandler)
|
|||||||
invoke(argument)
|
invoke(argument)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
handle_options = parser._handle_options
|
||||||
cur_arg = arguments[cur_arg_i]
|
cur_arg = arguments[cur_arg_i]
|
||||||
commands = parser._commands
|
commands = parser._commands
|
||||||
com_context = {}
|
com_context = {}
|
||||||
@@ -891,7 +896,6 @@ function Parser:_parse(args, errhandler)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function mainloop()
|
local function mainloop()
|
||||||
local handle_options = true
|
|
||||||
|
|
||||||
for _, data in ipairs(args) do
|
for _, data in ipairs(args) do
|
||||||
local plain = true
|
local plain = true
|
||||||
|
Reference in New Issue
Block a user