Skip to content

Commit 6b86aac

Browse files
committed
cli/command/stack/formatter: StackWrite: remove intermediate vars
- inline the closure - remove newStackContext() constructor and inline it Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 8b01d8e commit 6b86aac

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

cli/command/stack/formatter/formatter.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,29 @@ type Stack struct {
4444
//
4545
// Deprecated: this function was for internal use and will be removed in the next release.
4646
func StackWrite(ctx formatter.Context, stacks []*Stack) error {
47-
render := func(format func(subContext formatter.SubContext) error) error {
47+
fmtCtx := &stackContext{
48+
HeaderContext: formatter.HeaderContext{
49+
Header: formatter.SubHeaderContext{
50+
"Name": formatter.NameHeader,
51+
"Services": stackServicesHeader,
52+
},
53+
},
54+
}
55+
return ctx.Write(fmtCtx, func(format func(subContext formatter.SubContext) error) error {
4856
for _, stack := range stacks {
4957
if err := format(&stackContext{s: stack}); err != nil {
5058
return err
5159
}
5260
}
5361
return nil
54-
}
55-
return ctx.Write(newStackContext(), render)
62+
})
5663
}
5764

5865
type stackContext struct {
5966
formatter.HeaderContext
6067
s *Stack
6168
}
6269

63-
func newStackContext() *stackContext {
64-
stackCtx := stackContext{}
65-
stackCtx.Header = formatter.SubHeaderContext{
66-
"Name": formatter.NameHeader,
67-
"Services": stackServicesHeader,
68-
}
69-
return &stackCtx
70-
}
71-
7270
func (s *stackContext) MarshalJSON() ([]byte, error) {
7371
return formatter.MarshalJSON(s)
7472
}

0 commit comments

Comments
 (0)