Skip to content

Commit 4f491ff

Browse files
ndeloofglours
authored andcommitted
fix panic using w shortcut on project without watch support
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent ea1c26d commit 4f491ff

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

cmd/formatter/shortcut.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"math"
2424
"os"
25+
"reflect"
2526
"syscall"
2627
"time"
2728

@@ -69,8 +70,9 @@ func (ke *KeyboardError) error() string {
6970
}
7071

7172
type KeyboardWatch struct {
72-
Watching bool
73-
Watcher Toggle
73+
Watching bool
74+
Watcher Toggle
75+
IsConfigured bool
7476
}
7577

7678
type Toggle interface {
@@ -90,7 +92,6 @@ type LogKeyboard struct {
9092
kError KeyboardError
9193
Watch KeyboardWatch
9294
IsDockerDesktopActive bool
93-
IsWatchConfigured bool
9495
logLevel KEYBOARD_LOG_LEVEL
9596
signalChannel chan<- os.Signal
9697
}
@@ -101,11 +102,11 @@ var KeyboardManager *LogKeyboard
101102
func NewKeyboardManager(isDockerDesktopActive bool, sc chan<- os.Signal, w bool, watcher Toggle) *LogKeyboard {
102103
KeyboardManager = &LogKeyboard{
103104
Watch: KeyboardWatch{
104-
Watching: w,
105-
Watcher: watcher,
105+
Watching: w,
106+
Watcher: watcher,
107+
IsConfigured: !reflect.ValueOf(watcher).IsNil(),
106108
},
107109
IsDockerDesktopActive: isDockerDesktopActive,
108-
IsWatchConfigured: true,
109110
logLevel: INFO,
110111
signalChannel: sc,
111112
}
@@ -267,7 +268,7 @@ func (lk *LogKeyboard) keyboardError(prefix string, err error) {
267268
}
268269

269270
func (lk *LogKeyboard) ToggleWatch(ctx context.Context, options api.UpOptions) {
270-
if !lk.IsWatchConfigured {
271+
if !lk.Watch.IsConfigured {
271272
return
272273
}
273274
if lk.Watch.Watching {
@@ -298,7 +299,7 @@ func (lk *LogKeyboard) HandleKeyEvents(ctx context.Context, event keyboard.KeyEv
298299
case 'v':
299300
lk.openDockerDesktop(ctx, project)
300301
case 'w':
301-
if !lk.IsWatchConfigured {
302+
if !lk.Watch.IsConfigured {
302303
// we try to open watch docs if DD is installed
303304
if lk.IsDockerDesktopActive {
304305
lk.openDDWatchDocs(ctx, project)

0 commit comments

Comments
 (0)