From 46622e83de82719cdd1505e15ec4f2b64832cc61 Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Fri, 31 May 2019 21:19:48 -0400 Subject: [PATCH] Remove support for disabling completion option It is disabled by default --- src/argparse.lua | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/argparse.lua b/src/argparse.lua index a0e5360..10422f8 100644 --- a/src/argparse.lua +++ b/src/argparse.lua @@ -204,9 +204,6 @@ local add_help = {"add_help", function(self, value) if self._help_option_idx then table.remove(self._options, self._help_option_idx) - if self._complete_option_idx and self._complete_option_idx > self._help_option_idx then - self._complete_option_idx = self._complete_option_idx - 1 - end self._help_option_idx = nil end @@ -231,35 +228,23 @@ local add_help = {"add_help", function(self, value) end} local add_complete = {"add_complete", function(self, value) - typecheck("add_complete", {"boolean", "string", "table"}, value) + typecheck("add_complete", {"nil", "string", "table"}, value) - if self._complete_option_idx then - table.remove(self._options, self._complete_option_idx) - if self._help_option_idx and self._help_option_idx > self._complete_option_idx then - self._help_option_idx = self._help_option_idx - 1 - end - self._complete_option_idx = nil - end + local complete = self:option() + :description "Output a shell completion script for the specified shell." + :args(1) + :choices {"bash", "zsh", "fish"} + :action(function(_, _, shell) + print(self["get_" .. shell .. "_complete"](self)) + os.exit(0) + end) if value then - local complete = self:option() - :description "Output a shell completion script for the specified shell." - :args(1) - :choices {"bash", "zsh", "fish"} - :action(function(_, _, shell) - print(self["get_" .. shell .. "_complete"](self)) - os.exit(0) - end) + complete = complete(value) + end - if value ~= true then - complete = complete(value) - end - - if not complete._name then - complete "--completion" - end - - self._complete_option_idx = #self._options + if not complete._name then + complete "--completion" end end}