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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-21 10:47:26 +02:00
parent 4405c0bd50
commit 570a17b3bc

View File

@ -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
})
}