fix RegisterFlagCompletionFunc concurrent map writes error (#1423)

* fix-RegisterFlagCompletionFunc-concurrent
* set to root command
* move to non-public fields
This commit is contained in:
silenceshell
2021-07-01 05:49:30 +08:00
committed by GitHub
parent 2dea4f2ef3
commit 3c8a19ecd3
3 changed files with 12 additions and 7 deletions

View File

@ -512,7 +512,7 @@ func writeLocalNonPersistentFlag(buf io.StringWriter, flag *pflag.Flag) {
// Setup annotations for go completions for registered flags
func prepareCustomAnnotationsForFlags(cmd *Command) {
for flag := range flagCompletionFunctions {
for flag := range cmd.Root().flagCompletionFunctions {
// Make sure the completion script calls the __*_go_custom_completion function for
// every registered flag. We need to do this here (and not when the flag was registered
// for completion) so that we can know the root command name for the prefix