Skip to content

Commit 570a17b

Browse files
committed
internal/commands: RegisterLegacy: remove redundant copy
The RegisterLegacy and Register functions register constructors for commands, so we should expect them to be a fresh copy that is not shared, which means that we can mutate the command in-place. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4405c0b commit 570a17b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

internal/commands/commands.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ func Register(f func(command.Cli) *cobra.Command) {
2222
// in an init function and is not safe for concurrent use.
2323
func RegisterLegacy(f func(command.Cli) *cobra.Command) {
2424
commands = append(commands, func(c command.Cli) *cobra.Command {
25-
cmd := f(c)
2625
if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" {
27-
return cmd
26+
return f(c)
2827
}
29-
cmdCopy := *cmd
30-
cmdCopy.Hidden = true
31-
cmdCopy.Aliases = []string{}
32-
return &cmdCopy
28+
cmd := f(c)
29+
cmd.Hidden = true
30+
cmd.Aliases = []string{}
31+
return cmd
3332
})
3433
}
3534

0 commit comments

Comments
 (0)