From c5af087ad0519ed2fc83b42c8a02b615dd68303a Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Wed, 22 May 2019 16:41:58 -0400 Subject: [PATCH] Save index of help option Instead of keeping it at the end of the options list. --- src/argparse.lua | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/argparse.lua b/src/argparse.lua index 402f14a..4a28d05 100644 --- a/src/argparse.lua +++ b/src/argparse.lua @@ -202,9 +202,9 @@ end} local add_help = {"add_help", function(self, value) typecheck("add_help", {"boolean", "string", "table"}, value) - if self._has_help then - table.remove(self._options) - self._has_help = false + if self._help_option_idx then + table.remove(self._options, self._help_option_idx) + self._help_option_idx = nil end if value then @@ -223,7 +223,7 @@ local add_help = {"add_help", function(self, value) help "-h" "--help" end - self._has_help = true + self._help_option_idx = #self._options end end} @@ -600,13 +600,7 @@ end function Parser:option(...) local option = Option(...) - - if self._has_help then - table.insert(self._options, #self._options, option) - else - table.insert(self._options, option) - end - + table.insert(self._options, option) return option end