mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Use boolean fields instead of _type to store element type
This commit is contained in:
@@ -135,19 +135,19 @@ end
|
|||||||
function Argument:make_type()
|
function Argument:make_type()
|
||||||
if self._maxcount == 1 then
|
if self._maxcount == 1 then
|
||||||
if self._maxargs == 0 then
|
if self._maxargs == 0 then
|
||||||
self._type = "flag"
|
self.flag = true
|
||||||
elseif self._maxargs == 1 and (self._minargs == 1 or self._mincount == 1) then
|
elseif self._maxargs == 1 and (self._minargs == 1 or self._mincount == 1) then
|
||||||
self._type = "arg"
|
self.arg = true
|
||||||
else
|
else
|
||||||
self._type = "multi-arg"
|
self.multiarg = true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if self._maxargs == 0 then
|
if self._maxargs == 0 then
|
||||||
self._type = "counter"
|
self.counter = true
|
||||||
elseif self._maxargs == 1 and self._minargs == 1 then
|
elseif self._maxargs == 1 and self._minargs == 1 then
|
||||||
self._type = "multi-count"
|
self.multicount = true
|
||||||
else
|
else
|
||||||
self._type = "multi-count multi-arg"
|
self.twodimensional = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -519,19 +519,19 @@ function Parser:parse(args)
|
|||||||
|
|
||||||
passed[element] = 0
|
passed[element] = 0
|
||||||
|
|
||||||
if element._type == "flag" then
|
if element.flag then
|
||||||
result[element._target] = true
|
result[element._target] = true
|
||||||
elseif element._type == "multi-arg" then
|
elseif element.multiarg then
|
||||||
result[element._target] = {}
|
result[element._target] = {}
|
||||||
elseif element._type == "counter" then
|
elseif element.counter then
|
||||||
if not overwrite then
|
if not overwrite then
|
||||||
result[element._target] = result[element._target]+1
|
result[element._target] = result[element._target]+1
|
||||||
end
|
end
|
||||||
elseif element._type == "multi-count" then
|
elseif element.multicount then
|
||||||
if overwrite then
|
if overwrite then
|
||||||
table.remove(result[element._target], 1)
|
table.remove(result[element._target], 1)
|
||||||
end
|
end
|
||||||
elseif element._type == "multi-count multi-arg" then
|
elseif element.twodimensional then
|
||||||
table.insert(result[element._target], {})
|
table.insert(result[element._target], {})
|
||||||
|
|
||||||
if overwrite then
|
if overwrite then
|
||||||
@@ -548,11 +548,11 @@ function Parser:parse(args)
|
|||||||
passed[element] = passed[element]+1
|
passed[element] = passed[element]+1
|
||||||
data = convert(element, data)
|
data = convert(element, data)
|
||||||
|
|
||||||
if element._type == "arg" then
|
if element.arg then
|
||||||
result[element._target] = data
|
result[element._target] = data
|
||||||
elseif element._type == "multi-arg" or element._type == "multi-count" then
|
elseif element.multiarg or element.multicount then
|
||||||
table.insert(result[element._target], data)
|
table.insert(result[element._target], data)
|
||||||
elseif element._type == "multi-count multi-arg" then
|
elseif element.twodimensional then
|
||||||
table.insert(result[element._target][#result[element._target]], data)
|
table.insert(result[element._target][#result[element._target]], data)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -579,7 +579,7 @@ function Parser:parse(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if element._action then
|
if element._action then
|
||||||
if element._type == "multi-count" or element._type == "multi-count multi-arg" then
|
if element.multicount or element.twodimensional then
|
||||||
element._action(result[element._target][#result[element._target]])
|
element._action(result[element._target][#result[element._target]])
|
||||||
else
|
else
|
||||||
element._action(result[element._target])
|
element._action(result[element._target])
|
||||||
@@ -602,9 +602,9 @@ function Parser:parse(args)
|
|||||||
opt_context[alias] = option
|
opt_context[alias] = option
|
||||||
end
|
end
|
||||||
|
|
||||||
if option._type == "counter" then
|
if option.counter then
|
||||||
result[option._target] = 0
|
result[option._target] = 0
|
||||||
elseif option._type == "multi-count" or option._type == "multi-count multi-arg" then
|
elseif option.multicount or option.twodimensional then
|
||||||
result[option._target] = {}
|
result[option._target] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user