Skip to content

Commit b346a4c

Browse files
authored
BUGFIX: avoid collisions in context with custom type (staticcheck/SA1029) (#4014)
1 parent 39be60d commit b346a4c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

commands/completion.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
//go:embed completion-scripts/completion.*.gotmpl
2020
var completionScripts embed.FS
2121

22+
type contextKey int
23+
24+
const contextKeyCompletionHandled contextKey = iota
25+
2226
func shellCompletionCommand() *cli.Command {
2327
supportedShells, templates, err := getCompletionSupportedShells()
2428
if err != nil {
@@ -45,7 +49,7 @@ func shellCompletionCommand() *cli.Command {
4549
cmd.ShellComplete(ctx, cmd)
4650
}
4751
// Mark that we handled completion so Action can skip
48-
return context.WithValue(ctx, "completionHandled", true), nil
52+
return context.WithValue(ctx, contextKeyCompletionHandled, true), nil
4953
}
5054
return ctx, nil
5155
},
@@ -60,7 +64,7 @@ func shellCompletionCommand() *cli.Command {
6064
},
6165
Action: func(ctx context.Context, cmd *cli.Command) error {
6266
// If completion was handled in Before, skip normal action
63-
if ctx.Value("completionHandled") != nil {
67+
if ctx.Value(contextKeyCompletionHandled) != nil {
6468
return nil
6569
}
6670

0 commit comments

Comments
 (0)