From d3c10410d6ceaf0874b5a646f02c88170be33d4c Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 23 Aug 2017 13:58:31 -0700 Subject: Fix a subcommand matching This PR fixes an issue where a subcommand matches the current set of commands being examined. Fixes issue https://github.com/posener/complete/issues/46 --- command.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'command.go') diff --git a/command.go b/command.go index eeeb9e0..de501d5 100644 --- a/command.go +++ b/command.go @@ -74,6 +74,12 @@ func (c *Command) predict(a Args) (options []string, only bool) { return } } + + // We matched so stop searching. Continuing to search can accidentally + // match a subcommand with current set of commands, see issue #46. + if subCommandFound { + break + } } // if last completed word is a global flag that we need to complete -- cgit v1.2.3 From 1c43d25e3519cc70fc238d669f7b2aa826ac716a Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 24 Aug 2017 11:08:51 -0700 Subject: Avoid unnecessary if statement --- command.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'command.go') diff --git a/command.go b/command.go index de501d5..9614269 100644 --- a/command.go +++ b/command.go @@ -73,11 +73,9 @@ func (c *Command) predict(a Args) (options []string, only bool) { if only { return } - } - // We matched so stop searching. Continuing to search can accidentally - // match a subcommand with current set of commands, see issue #46. - if subCommandFound { + // We matched so stop searching. Continuing to search can accidentally + // match a subcommand with current set of commands, see issue #46. break } } -- cgit v1.2.3