Skip to content

Commit b0d1d2d

Browse files
committed
Fix lkint
Signed-off-by: Joana Hrotko <[email protected]>
1 parent d75db0f commit b0d1d2d

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

Diff for: cmd/formatter/logs.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
108108
if l.ctx.Err() != nil {
109109
return
110110
}
111-
print := func() {
111+
printFn := func() {
112112
p := l.getPresenter(container)
113113
timestamp := time.Now().Format(jsonmessage.RFC3339NanoFixed)
114114
for _, line := range strings.Split(message, "\n") {
@@ -120,9 +120,9 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
120120
}
121121
}
122122
if KeyboardManager != nil {
123-
KeyboardManager.PrintKeyboardInfo(print)
123+
KeyboardManager.PrintKeyboardInfo(printFn)
124124
} else {
125-
print()
125+
printFn()
126126
}
127127
}
128128

Diff for: cmd/formatter/shortcut.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package formatter
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"math"
2324
"os"
@@ -62,7 +63,7 @@ func (ke *KeyboardError) addError(prefix string, err error) {
6263
prefix = ansiColor("1;36", fmt.Sprintf("%s →", prefix))
6364
errorString := fmt.Sprintf("%s %s", prefix, err.Error())
6465

65-
ke.err = fmt.Errorf(errorString)
66+
ke.err = errors.New(errorString)
6667
}
6768

6869
func (ke *KeyboardError) error() string {
@@ -113,7 +114,14 @@ type LogKeyboard struct {
113114
var KeyboardManager *LogKeyboard
114115
var eg multierror.Group
115116

116-
func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<- os.Signal, watchFn func(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error) {
117+
func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool,
118+
sc chan<- os.Signal,
119+
watchFn func(ctx context.Context,
120+
project *types.Project,
121+
services []string,
122+
options api.WatchOptions,
123+
) error,
124+
) {
117125
km := LogKeyboard{}
118126
km.IsDockerDesktopActive = isDockerDesktopActive
119127
km.IsWatchConfigured = isWatchConfigured
@@ -134,9 +142,9 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<-
134142
HideCursor()
135143
}
136144

137-
func (lk *LogKeyboard) PrintKeyboardInfo(print func()) {
145+
func (lk *LogKeyboard) PrintKeyboardInfo(printFn func()) {
138146
lk.clearNavigationMenu()
139-
print()
147+
printFn()
140148

141149
if lk.logLevel == INFO {
142150
lk.createBuffer(0)
@@ -151,13 +159,13 @@ func (lk *LogKeyboard) createBuffer(lines int) {
151159
if lk.kError.shoudlDisplay() {
152160
extraLines := linesOffset(lk.kError.error()) + 1
153161
allocateSpace(extraLines)
154-
lines = lines + extraLines
162+
lines += extraLines
155163
}
156164

157165
infoMessage := lk.navigationMenu()
158166
extraLines := linesOffset(infoMessage) + 1
159167
allocateSpace(extraLines)
160-
lines = lines + extraLines
168+
lines += extraLines
161169

162170
if lines > 0 {
163171
MoveCursorUp(lines)
@@ -259,6 +267,10 @@ func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, o
259267
}
260268
}
261269

270+
func (lk *LogKeyboard) KeyboardClose() {
271+
_ = keyboard.Close()
272+
}
273+
262274
func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Context, project *types.Project, options api.UpOptions) {
263275
switch kRune := event.Rune; kRune {
264276
case 'V':
@@ -269,7 +281,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
269281
}
270282
switch key := event.Key; key {
271283
case keyboard.KeyCtrlC:
272-
keyboard.Close()
284+
lk.KeyboardClose()
273285

274286
lk.clearNavigationMenu()
275287
ShowCursor()
@@ -281,7 +293,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
281293
}
282294
go func() {
283295
// Send telemetry
284-
tracing.SpanWrapFunc("navigation_menu", tracing.KeyboardOptions(lk.metrics),
296+
_ = tracing.SpanWrapFunc("navigation_menu", tracing.KeyboardOptions(lk.metrics),
285297
func(ctx context.Context) error {
286298
return nil
287299
})(ctx)

Diff for: pkg/compose/up.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
9999
if options.Start.Watch {
100100
formatter.KeyboardManager.StartWatch(ctx, project, options)
101101
}
102-
defer keyboard.Close()
102+
defer formatter.KeyboardManager.KeyboardClose()
103103
}
104104
for {
105105
select {

Diff for: pkg/compose/watch.go

-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
175175
})
176176
}
177177
if !watching {
178-
// options.LogTo.Err(api.WatchLogger, "FAILED")
179178
return fmt.Errorf("none of the selected services is configured for watch, consider setting an 'develop' section")
180179
}
181180
options.LogTo.Log(api.WatchLogger, "Watch started")

0 commit comments

Comments
 (0)