Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <joana.hrotko@docker.com>
  • Loading branch information
jhrotko committed Mar 18, 2024
1 parent 9ec0c08 commit 11189b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cmd/formatter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
if l.ctx.Err() != nil {
return
}
print := func() {
printFn := func() {
p := l.getPresenter(container)
timestamp := time.Now().Format(jsonmessage.RFC3339NanoFixed)
for _, line := range strings.Split(message, "\n") {
Expand All @@ -120,9 +120,9 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
}
}
if KeyboardManager != nil {
KeyboardManager.PrintKeyboardInfo(print)
KeyboardManager.PrintKeyboardInfo(printFn)
} else {
print()
printFn()
}
}

Expand Down
28 changes: 20 additions & 8 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package formatter

import (
"context"
"errors"
"fmt"
"math"
"os"
Expand Down Expand Up @@ -62,7 +63,7 @@ func (ke *KeyboardError) addError(prefix string, err error) {
prefix = ansiColor("1;36", fmt.Sprintf("%s →", prefix))
errorString := fmt.Sprintf("%s %s", prefix, err.Error())

ke.err = fmt.Errorf(errorString)
ke.err = errors.New(errorString)
}

func (ke *KeyboardError) error() string {
Expand Down Expand Up @@ -113,7 +114,14 @@ type LogKeyboard struct {
var KeyboardManager *LogKeyboard
var eg multierror.Group

func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<- os.Signal, watchFn func(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error) {
func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool,
sc chan<- os.Signal,
watchFn func(ctx context.Context,
project *types.Project,
services []string,
options api.WatchOptions,
) error,
) {
km := LogKeyboard{}
km.IsDockerDesktopActive = isDockerDesktopActive
km.IsWatchConfigured = isWatchConfigured
Expand All @@ -134,9 +142,9 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<-
HideCursor()
}

func (lk *LogKeyboard) PrintKeyboardInfo(print func()) {
func (lk *LogKeyboard) PrintKeyboardInfo(printFn func()) {
lk.clearNavigationMenu()
print()
printFn()

if lk.logLevel == INFO {
lk.createBuffer(0)
Expand All @@ -151,13 +159,13 @@ func (lk *LogKeyboard) createBuffer(lines int) {
if lk.kError.shoudlDisplay() {
extraLines := linesOffset(lk.kError.error()) + 1
allocateSpace(extraLines)
lines = lines + extraLines
lines += extraLines
}

infoMessage := lk.navigationMenu()
extraLines := linesOffset(infoMessage) + 1
allocateSpace(extraLines)
lines = lines + extraLines
lines += extraLines

if lines > 0 {
MoveCursorUp(lines)
Expand Down Expand Up @@ -259,6 +267,10 @@ func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, o
}
}

func (lk *LogKeyboard) KeyboardClose() {
_ = keyboard.Close()
}

func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Context, project *types.Project, options api.UpOptions) {
switch kRune := event.Rune; kRune {
case 'V':
Expand All @@ -269,7 +281,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
}
switch key := event.Key; key {
case keyboard.KeyCtrlC:
keyboard.Close()
lk.KeyboardClose()

lk.clearNavigationMenu()
ShowCursor()
Expand All @@ -281,7 +293,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
}
go func() {
// Send telemetry
tracing.SpanWrapFunc("navigation_menu", tracing.KeyboardOptions(lk.metrics),
_ = tracing.SpanWrapFunc("navigation_menu", tracing.KeyboardOptions(lk.metrics),
func(ctx context.Context) error {
return nil
})(ctx)
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
if options.Start.Watch {
formatter.KeyboardManager.StartWatch(ctx, project, options)
}
defer keyboard.Close()
defer formatter.KeyboardManager.KeyboardClose()
}
for {
select {
Expand Down
1 change: 0 additions & 1 deletion pkg/compose/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
})
}
if !watching {
// options.LogTo.Err(api.WatchLogger, "FAILED")
return fmt.Errorf("none of the selected services is configured for watch, consider setting an 'develop' section")
}
options.LogTo.Log(api.WatchLogger, "Watch started")
Expand Down

0 comments on commit 11189b2

Please sign in to comment.