Skip to content

Commit 178be30

Browse files
committed
uid: fix cmd for persistent flag
1 parent bedfad9 commit 178be30

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/uid/uid.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"strings"
9+
"sync"
910

1011
"github.com/carapace-sh/carapace/internal/pflagfork"
1112
"github.com/spf13/cobra"
@@ -38,8 +39,17 @@ func reverse(s []string) {
3839
}
3940
}
4041

42+
var flagMutex sync.RWMutex
43+
4144
// Flag creates a uid for given flag.
4245
func Flag(cmd *cobra.Command, flag *pflagfork.Flag) *url.URL {
46+
// TODO dirty quickfix to avoid concurrent map write when modifying the `formal` map in FlagSet.AddFlag
47+
flagMutex.Lock()
48+
defer flagMutex.Unlock()
49+
50+
if cmd.LocalFlags().Lookup(flag.Name) == nil && cmd.HasParent() {
51+
return Flag(cmd.Parent(), flag)
52+
}
4353
uid := Command(cmd)
4454
values := uid.Query()
4555
values.Set("flag", flag.Name)

0 commit comments

Comments
 (0)