From 3c47a5a9c87f431fd871d840dc0464de898bbed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 5 Oct 2023 23:51:52 +0300 Subject: [PATCH] Avoid some unnecessary looping --- cobra.go | 2 -- flag_groups.go | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cobra.go b/cobra.go index f23f5092..e403e762 100644 --- a/cobra.go +++ b/cobra.go @@ -188,8 +188,6 @@ func ld(s, t string, ignoreCase bool) int { d := make([][]int, len(s)+1) for i := range d { d[i] = make([]int, len(t)+1) - } - for i := range d { d[i][0] = i } for j := range d[0] { diff --git a/flag_groups.go b/flag_groups.go index 6e938325..2be3b18b 100644 --- a/flag_groups.go +++ b/flag_groups.go @@ -253,17 +253,17 @@ func (c *Command) enforceFlagGroupsForCompletion() { // If none of the flags of a one-required group are present, we make all the flags // of that group required so that the shell completion suggests them automatically for flagList, flagnameAndStatus := range oneRequiredGroupStatus { - set := 0 + isSet := false - for _, isSet := range flagnameAndStatus { + for _, isSet = range flagnameAndStatus { if isSet { - set++ + break } } // None of the flags of the group are set, mark all flags in the group // as required - if set == 0 { + if !isSet { for _, fName := range strings.Split(flagList, " ") { _ = c.MarkFlagRequired(fName) }