mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Save index of help option
Instead of keeping it at the end of the options list.
This commit is contained in:
@@ -202,9 +202,9 @@ end}
|
|||||||
local add_help = {"add_help", function(self, value)
|
local add_help = {"add_help", function(self, value)
|
||||||
typecheck("add_help", {"boolean", "string", "table"}, value)
|
typecheck("add_help", {"boolean", "string", "table"}, value)
|
||||||
|
|
||||||
if self._has_help then
|
if self._help_option_idx then
|
||||||
table.remove(self._options)
|
table.remove(self._options, self._help_option_idx)
|
||||||
self._has_help = false
|
self._help_option_idx = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if value then
|
if value then
|
||||||
@@ -223,7 +223,7 @@ local add_help = {"add_help", function(self, value)
|
|||||||
help "-h" "--help"
|
help "-h" "--help"
|
||||||
end
|
end
|
||||||
|
|
||||||
self._has_help = true
|
self._help_option_idx = #self._options
|
||||||
end
|
end
|
||||||
end}
|
end}
|
||||||
|
|
||||||
@@ -600,13 +600,7 @@ end
|
|||||||
|
|
||||||
function Parser:option(...)
|
function Parser:option(...)
|
||||||
local option = Option(...)
|
local option = Option(...)
|
||||||
|
table.insert(self._options, option)
|
||||||
if self._has_help then
|
|
||||||
table.insert(self._options, #self._options, option)
|
|
||||||
else
|
|
||||||
table.insert(self._options, option)
|
|
||||||
end
|
|
||||||
|
|
||||||
return option
|
return option
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user