Skip to content

Commit 893dd4d

Browse files
committed
Support use of debug --tui to render debuggable containers
Signed-off-by: Evan Harris <[email protected]>
1 parent 69ec407 commit 893dd4d

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

pkg/app/master/command/debug/cli.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/mintoolkit/mint/pkg/app"
1010
"github.com/mintoolkit/mint/pkg/app/master/command"
11+
"github.com/mintoolkit/mint/pkg/app/master/tui"
1112
"github.com/mintoolkit/mint/pkg/crt"
1213
)
1314

@@ -172,6 +173,15 @@ var CLI = &cli.Command{
172173
},
173174
Action: func(ctx *cli.Context) error {
174175
gcvalues := command.GlobalFlagValues(ctx)
176+
177+
// If we stick with this approach, the user should be communicated to
178+
// use `--tui` as a standalone flag for `debug`
179+
if ctx.Bool(command.FlagTUI) {
180+
initialTUI := InitialTUI(true, gcvalues)
181+
tui.RunTUI(initialTUI, true)
182+
return nil
183+
}
184+
175185
xc := app.NewExecutionContext(
176186
Name,
177187
gcvalues.QuietCLIMode,
@@ -284,7 +294,7 @@ var CLI = &cli.Command{
284294
!commandParams.ActionConnectSession &&
285295
commandParams.TargetRef == "" {
286296
if ctx.Args().Len() < 1 {
287-
if !commandParams.TUI && commandParams.Runtime != crt.KubernetesRuntime {
297+
if commandParams.Runtime != crt.KubernetesRuntime {
288298
xc.Out.Error("param.target", "missing target")
289299
cli.ShowCommandHelp(ctx, Name)
290300
return nil

pkg/app/master/command/debug/handler.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/mintoolkit/mint/pkg/app"
99
"github.com/mintoolkit/mint/pkg/app/master/command"
10-
"github.com/mintoolkit/mint/pkg/app/master/tui"
1110
"github.com/mintoolkit/mint/pkg/app/master/version"
1211
cmd "github.com/mintoolkit/mint/pkg/command"
1312
"github.com/mintoolkit/mint/pkg/crt"
@@ -84,11 +83,6 @@ func OnCommand(
8483
resolved := command.ResolveAutoRuntime(commandParams.Runtime)
8584
logger.Tracef("runtime.handler: rt=%s resolved=%s", commandParams.Runtime, resolved)
8685

87-
if commandParams.TUI { // `debug --tui``
88-
initialTUI := InitialTUI(true)
89-
tui.RunTUI(initialTUI, true)
90-
}
91-
9286
switch resolved {
9387
case crt.DockerRuntime:
9488
client, err := dockerclient.New(gparams.ClientConfig)

pkg/app/master/command/debug/tui.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type TUI struct {
2424
table table.Table
2525

2626
showDebuggableContainers bool
27+
28+
gcvalues *command.GenericParams
2729
}
2830

2931
// Styles - move to `common`
@@ -58,11 +60,12 @@ func LoadTUI() *TUI {
5860
}
5961

6062
// InitialTUI returns the initial state of the model.
61-
func InitialTUI(standalone bool) *TUI {
63+
func InitialTUI(standalone bool, gcvalues *command.GenericParams) *TUI {
6264
m := &TUI{
6365
standalone: standalone,
6466
width: 20,
6567
height: 15,
68+
gcvalues: gcvalues,
6669
}
6770

6871
return m
@@ -156,6 +159,7 @@ func (m TUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
156159
}()
157160

158161
<-doneCh
162+
m.showDebuggableContainers = !m.showDebuggableContainers
159163
return m, nil
160164
case tea.KeyMsg:
161165
switch {
@@ -166,6 +170,17 @@ func (m TUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
166170
case key.Matches(msg, keys.Global.Back):
167171
return common.TUIsInstance.Home, nil
168172
case key.Matches(msg, keys.Debug.LoadDebuggableContainers):
173+
// Kickoff loading of debuggable containers in standable.
174+
if m.standalone {
175+
loadDebuggableContainers := common.Event{
176+
Type: common.LaunchDebugEvent,
177+
Data: m.gcvalues,
178+
}
179+
m, _ := m.Update(loadDebuggableContainers)
180+
return m, nil
181+
}
182+
183+
// When used via `tui -> debug`
169184
m.showDebuggableContainers = !m.showDebuggableContainers
170185
return m, nil
171186

@@ -215,12 +230,13 @@ func (m TUI) View() string {
215230
// 4. Connect to a debug session
216231
// 5. Start a new debug session
217232

218-
content := "Debug View"
233+
content := "Debug Dashboard\n"
219234

220235
components = append(components, content)
221236

222237
if m.showDebuggableContainers {
223-
components = append(components, m.table.String())
238+
header := "Debuggable Containers\n"
239+
components = append(components, header, m.table.String())
224240
}
225241

226242
components = append(components, m.help())
@@ -231,8 +247,17 @@ func (m TUI) View() string {
231247
}
232248

233249
func (m TUI) help() string {
250+
var listOrHide string
251+
252+
if m.showDebuggableContainers {
253+
listOrHide = "hide"
254+
} else {
255+
listOrHide = "list"
256+
}
257+
234258
if m.standalone {
235-
return common.HelpStyle("• l list debuggable containers • q: quit")
259+
return common.HelpStyle("• l: " + listOrHide + " debuggable containers • q: quit")
236260
}
237-
return common.HelpStyle("• l list debuggable containers • esc: back • q: quit")
261+
262+
return common.HelpStyle("• l: " + listOrHide + " debuggable containers • esc: back • q: quit")
238263
}

0 commit comments

Comments
 (0)