Skip to content

Commit b067830

Browse files
committed
Introduce navigation-menu option in up
Signed-off-by: Joana Hrotko <[email protected]>
1 parent 992e6b8 commit b067830

File tree

4 files changed

+71
-48
lines changed

4 files changed

+71
-48
lines changed

Diff for: cmd/compose/up.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type upOptions struct {
5555
wait bool
5656
waitTimeout int
5757
watch bool
58+
navigationBar bool
5859
}
5960

6061
func (opts upOptions) apply(project *types.Project, services []string) (*types.Project, error) {
@@ -127,6 +128,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
127128
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
128129
flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "Maximum duration to wait for the project to be running|healthy")
129130
flags.BoolVarP(&up.watch, "watch", "w", false, "Watch source code and rebuild/refresh containers when files are updated.")
131+
flags.BoolVar(&up.navigationBar, "navigation-menu", true, "While running in attach mode, enable shortcuts and shortcuts info bar.")
130132

131133
return upCmd
132134
}
@@ -251,15 +253,16 @@ func runUp(
251253
return backend.Up(ctx, project, api.UpOptions{
252254
Create: create,
253255
Start: api.StartOptions{
254-
Project: project,
255-
Attach: consumer,
256-
AttachTo: attach,
257-
ExitCodeFrom: upOptions.exitCodeFrom,
258-
CascadeStop: upOptions.cascadeStop,
259-
Wait: upOptions.wait,
260-
WaitTimeout: timeout,
261-
Watch: upOptions.watch,
262-
Services: services,
256+
Project: project,
257+
Attach: consumer,
258+
AttachTo: attach,
259+
ExitCodeFrom: upOptions.exitCodeFrom,
260+
CascadeStop: upOptions.cascadeStop,
261+
Wait: upOptions.wait,
262+
WaitTimeout: timeout,
263+
Watch: upOptions.watch,
264+
Services: services,
265+
NavigationBar: upOptions.navigationBar,
263266
},
264267
})
265268
}

Diff for: cmd/formatter/shortcut.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ var KeyboardManager *LogKeyboard
3838

3939
var errorColor = "\x1b[1;33m"
4040

41-
func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, watchFn func(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error) {
41+
func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured, startWatch bool, watchFn func(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error) {
4242
km := LogKeyboard{}
4343
KeyboardManager = &km
44-
KeyboardManager.Watch.Watching = true
4544
KeyboardManager.IsDockerDesktopActive = isDockerDesktopActive
4645
KeyboardManager.IsWatchConfigured = isWatchConfigured
46+
// if up --watch and there is a watch config, we should start with watch running
47+
KeyboardManager.Watch.Watching = isWatchConfigured && startWatch
4748
KeyboardManager.Watch.WatchFn = watchFn
4849
}
4950

@@ -144,8 +145,6 @@ func (lk *LogKeyboard) openDockerDesktop(project *types.Project) {
144145
err := open.Run(link)
145146
if err != nil {
146147
lk.Error("View", fmt.Errorf("could not open Docker Desktop"))
147-
} else {
148-
lk.Error("", nil)
149148
}
150149
}
151150
}
@@ -189,9 +188,5 @@ func (lk *LogKeyboard) HandleKeyEvents(ctx context.Context, event keyboard.KeyEv
189188
handleTearDown()
190189
case keyboard.KeyEnter:
191190
lk.PrintEnter()
192-
default:
193-
if key != 0 { // If some key is pressed
194-
fmt.Println("key pressed: ", key)
195-
}
196191
}
197192
}

Diff for: pkg/api/api.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ type StartOptions struct {
217217
Wait bool
218218
WaitTimeout time.Duration
219219
// Services passed in the command line to be started
220-
Services []string
221-
Watch bool
220+
Services []string
221+
Watch bool
222+
NavigationBar bool
222223
}
223224

224225
// RestartOptions group options of the Restart API

Diff for: pkg/compose/up.go

+53-29
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
7373

7474
doneCh := make(chan bool)
7575
eg.Go(func() error {
76-
kEvents, err := keyboard.GetKeys(100)
77-
if err != nil {
78-
panic(err)
79-
}
80-
formatter.NewKeyboardManager(true, false, s.Watch) // change after test
81-
// kManager.IsDockerDesktopActive = s.isDesktopIntegrationActive()
82-
// kManager.IsWatchConfigured = s.shouldWatch(project)
83-
defer keyboard.Close()
84-
8576
first := true
8677
gracefulTeardown := func() {
8778
printer.Cancel()
@@ -97,27 +88,60 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
9788
})
9889
first = false
9990
}
100-
for {
101-
select {
102-
case event := <-kEvents:
103-
formatter.KeyboardManager.HandleKeyEvents(ctx, event, project, options, gracefulTeardown)
104-
case <-doneCh:
105-
return nil
106-
case <-ctx.Done():
107-
if first {
108-
gracefulTeardown()
109-
}
110-
case <-signalChan:
111-
if first {
112-
gracefulTeardown()
113-
} else {
114-
eg.Go(func() error {
115-
return s.Kill(context.Background(), project.Name, api.KillOptions{
116-
Services: options.Create.Services,
117-
Project: project,
91+
92+
if options.Start.NavigationBar {
93+
kEvents, err := keyboard.GetKeys(100)
94+
if err != nil {
95+
panic(err)
96+
}
97+
formatter.NewKeyboardManager(true, false, options.Start.Watch, s.Watch) // change after test
98+
// formatter.NewKeyboardManager(s.isDesktopIntegrationActive(), s.shouldWatch(project), s.Watch)
99+
defer keyboard.Close()
100+
for {
101+
select {
102+
case event := <-kEvents:
103+
formatter.KeyboardManager.HandleKeyEvents(ctx, event, project, options, gracefulTeardown)
104+
case <-doneCh:
105+
return nil
106+
case <-ctx.Done():
107+
if first {
108+
gracefulTeardown()
109+
}
110+
case <-signalChan:
111+
if first {
112+
gracefulTeardown()
113+
} else {
114+
eg.Go(func() error {
115+
return s.Kill(context.Background(), project.Name, api.KillOptions{
116+
Services: options.Create.Services,
117+
Project: project,
118+
})
118119
})
119-
})
120+
return nil
121+
}
122+
}
123+
}
124+
} else {
125+
for {
126+
select {
127+
case <-doneCh:
120128
return nil
129+
case <-ctx.Done():
130+
if first {
131+
gracefulTeardown()
132+
}
133+
case <-signalChan:
134+
if first {
135+
gracefulTeardown()
136+
} else {
137+
eg.Go(func() error {
138+
return s.Kill(context.Background(), project.Name, api.KillOptions{
139+
Services: options.Create.Services,
140+
Project: project,
141+
})
142+
})
143+
return nil
144+
}
121145
}
122146
}
123147
}
@@ -138,7 +162,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
138162
return err
139163
})
140164

141-
if options.Start.Watch {
165+
if options.Start.Watch && !options.Start.NavigationBar {
142166
eg.Go(func() error {
143167
buildOpts := *options.Create.Build
144168
buildOpts.Quiet = true

0 commit comments

Comments
 (0)