mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Reorder properties
Move more common properties to the front of property lists, so that they can be passed as constructor arguments. E.g. parser:option "-p" "--port" :description "Port number." :default "8080" :convert(tonumber) can now be expressed as parser:option("-p --port", "Port number.", "8080", tonumber)
This commit is contained in:
@@ -60,10 +60,7 @@ describe("tests related to default values", function()
|
|||||||
|
|
||||||
it("handles option with default value for multi-argument option correctly", function()
|
it("handles option with default value for multi-argument option correctly", function()
|
||||||
local parser = Parser()
|
local parser = Parser()
|
||||||
parser:option "-s" "--several" {
|
parser:option("-s --several", "Two or three things", "foo", nil, "2-3")
|
||||||
default = "foo",
|
|
||||||
args = "2-3"
|
|
||||||
}
|
|
||||||
local args = parser:parse{}
|
local args = parser:parse{}
|
||||||
assert.same({several = {"foo", "foo"}}, args)
|
assert.same({several = {"foo", "foo"}}, args)
|
||||||
end)
|
end)
|
||||||
|
@@ -31,19 +31,17 @@ Options:
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("uses description and epilog", function()
|
it("uses description and epilog", function()
|
||||||
local parser = Parser "foo"
|
local parser = Parser("foo", "A description.", "An epilog.")
|
||||||
:description "A description. "
|
|
||||||
:epilog "An epilog. "
|
|
||||||
|
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: foo [-h]
|
Usage: foo [-h]
|
||||||
|
|
||||||
A description.
|
A description.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help Show this help message and exit.
|
-h, --help Show this help message and exit.
|
||||||
|
|
||||||
An epilog. ]], parser:get_help())
|
An epilog.]], parser:get_help())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("creates correct help message for arguments", function()
|
it("creates correct help message for arguments", function()
|
||||||
|
@@ -152,9 +152,7 @@ describe("tests related to options", function()
|
|||||||
describe("Options with optional argument", function()
|
describe("Options with optional argument", function()
|
||||||
it("handles emptiness correctly", function()
|
it("handles emptiness correctly", function()
|
||||||
local parser = Parser()
|
local parser = Parser()
|
||||||
parser:option "-p" "--password" {
|
parser:option("-p --password", "Secure password for special security", nil, nil, "?")
|
||||||
args = "?"
|
|
||||||
}
|
|
||||||
local args = parser:parse({})
|
local args = parser:parse({})
|
||||||
assert.same({}, args)
|
assert.same({}, args)
|
||||||
end)
|
end)
|
||||||
|
@@ -218,13 +218,13 @@ local Argument = new_class({
|
|||||||
}, {
|
}, {
|
||||||
typechecked("name", "string"),
|
typechecked("name", "string"),
|
||||||
typechecked("description", "string"),
|
typechecked("description", "string"),
|
||||||
typechecked("target", "string"),
|
|
||||||
boundaries("args"),
|
|
||||||
typechecked("default", "string"),
|
typechecked("default", "string"),
|
||||||
|
typechecked("convert", "function", "table"),
|
||||||
|
boundaries("args"),
|
||||||
|
typechecked("target", "string"),
|
||||||
typechecked("defmode", "string"),
|
typechecked("defmode", "string"),
|
||||||
typechecked("show_default", "boolean"),
|
typechecked("show_default", "boolean"),
|
||||||
typechecked("argname", "string", "table"),
|
typechecked("argname", "string", "table")
|
||||||
typechecked("convert", "function", "table")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local Option = new_class({
|
local Option = new_class({
|
||||||
@@ -234,15 +234,15 @@ local Option = new_class({
|
|||||||
}, {
|
}, {
|
||||||
multiname,
|
multiname,
|
||||||
typechecked("description", "string"),
|
typechecked("description", "string"),
|
||||||
typechecked("target", "string"),
|
typechecked("default", "string"),
|
||||||
|
typechecked("convert", "function", "table"),
|
||||||
boundaries("args"),
|
boundaries("args"),
|
||||||
boundaries("count"),
|
boundaries("count"),
|
||||||
typechecked("default", "string"),
|
typechecked("target", "string"),
|
||||||
typechecked("defmode", "string"),
|
typechecked("defmode", "string"),
|
||||||
typechecked("show_default", "boolean"),
|
typechecked("show_default", "boolean"),
|
||||||
typechecked("overwrite", "boolean"),
|
typechecked("overwrite", "boolean"),
|
||||||
typechecked("argname", "string", "table"),
|
typechecked("argname", "string", "table"),
|
||||||
typechecked("convert", "function", "table"),
|
|
||||||
typechecked("action", "function")
|
typechecked("action", "function")
|
||||||
}, Argument)
|
}, Argument)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user