From 6b86aac02e04e6ab0cf04360408609fe8680f4b9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Aug 2025 15:30:23 +0200 Subject: [PATCH] cli/command/stack/formatter: StackWrite: remove intermediate vars - inline the closure - remove newStackContext() constructor and inline it Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/formatter/formatter.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cli/command/stack/formatter/formatter.go b/cli/command/stack/formatter/formatter.go index 7cfe8a89af..9d92bfd6e2 100644 --- a/cli/command/stack/formatter/formatter.go +++ b/cli/command/stack/formatter/formatter.go @@ -44,15 +44,22 @@ type Stack struct { // // Deprecated: this function was for internal use and will be removed in the next release. func StackWrite(ctx formatter.Context, stacks []*Stack) error { - render := func(format func(subContext formatter.SubContext) error) error { + fmtCtx := &stackContext{ + HeaderContext: formatter.HeaderContext{ + Header: formatter.SubHeaderContext{ + "Name": formatter.NameHeader, + "Services": stackServicesHeader, + }, + }, + } + return ctx.Write(fmtCtx, func(format func(subContext formatter.SubContext) error) error { for _, stack := range stacks { if err := format(&stackContext{s: stack}); err != nil { return err } } return nil - } - return ctx.Write(newStackContext(), render) + }) } type stackContext struct { @@ -60,15 +67,6 @@ type stackContext struct { s *Stack } -func newStackContext() *stackContext { - stackCtx := stackContext{} - stackCtx.Header = formatter.SubHeaderContext{ - "Name": formatter.NameHeader, - "Services": stackServicesHeader, - } - return &stackCtx -} - func (s *stackContext) MarshalJSON() ([]byte, error) { return formatter.MarshalJSON(s) }