From 570a17b3bcd9fd2da4dfc815fe105d0df136eb50 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 21 Aug 2025 10:47:26 +0200 Subject: [PATCH] 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 --- internal/commands/commands.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/commands/commands.go b/internal/commands/commands.go index b838de4518..2a1750625c 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -22,14 +22,13 @@ func Register(f func(command.Cli) *cobra.Command) { // in an init function and is not safe for concurrent use. func RegisterLegacy(f func(command.Cli) *cobra.Command) { commands = append(commands, func(c command.Cli) *cobra.Command { - cmd := f(c) if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" { - return cmd + return f(c) } - cmdCopy := *cmd - cmdCopy.Hidden = true - cmdCopy.Aliases = []string{} - return &cmdCopy + cmd := f(c) + cmd.Hidden = true + cmd.Aliases = []string{} + return cmd }) }