mirror of
https://github.com/spf13/cobra
synced 2025-04-27 17:17:20 +00:00
Avoid some unnecessary looping
This commit is contained in:
parent
34416a2637
commit
3c47a5a9c8
2 changed files with 4 additions and 6 deletions
2
cobra.go
2
cobra.go
|
@ -188,8 +188,6 @@ func ld(s, t string, ignoreCase bool) int {
|
||||||
d := make([][]int, len(s)+1)
|
d := make([][]int, len(s)+1)
|
||||||
for i := range d {
|
for i := range d {
|
||||||
d[i] = make([]int, len(t)+1)
|
d[i] = make([]int, len(t)+1)
|
||||||
}
|
|
||||||
for i := range d {
|
|
||||||
d[i][0] = i
|
d[i][0] = i
|
||||||
}
|
}
|
||||||
for j := range d[0] {
|
for j := range d[0] {
|
||||||
|
|
|
@ -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
|
// 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
|
// of that group required so that the shell completion suggests them automatically
|
||||||
for flagList, flagnameAndStatus := range oneRequiredGroupStatus {
|
for flagList, flagnameAndStatus := range oneRequiredGroupStatus {
|
||||||
set := 0
|
isSet := false
|
||||||
|
|
||||||
for _, isSet := range flagnameAndStatus {
|
for _, isSet = range flagnameAndStatus {
|
||||||
if isSet {
|
if isSet {
|
||||||
set++
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// None of the flags of the group are set, mark all flags in the group
|
// None of the flags of the group are set, mark all flags in the group
|
||||||
// as required
|
// as required
|
||||||
if set == 0 {
|
if !isSet {
|
||||||
for _, fName := range strings.Split(flagList, " ") {
|
for _, fName := range strings.Split(flagList, " ") {
|
||||||
_ = c.MarkFlagRequired(fName)
|
_ = c.MarkFlagRequired(fName)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue