Skip to content

Commit 9a5fd7f

Browse files
committed
wip
1 parent 2df99ce commit 9a5fd7f

6 files changed

Lines changed: 53 additions & 41 deletions

File tree

pkg/cli/cmd/radinit/display.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (r *Runner) confirmOptions(ctx context.Context, options *initOptions) (bool
7878
}
7979

8080
switch model.(*summaryModel).result {
81-
case resultConfimed:
81+
case resultConfirmed:
8282
return true, nil
8383
case resultCanceled:
8484
return false, nil
@@ -94,7 +94,7 @@ func (r *Runner) confirmOptions(ctx context.Context, options *initOptions) (bool
9494
// This function should be called from a goroutine while installation proceeds in the background.
9595
// provide a channel to update progress.
9696
func (r *Runner) showProgress(ctx context.Context, options *initOptions, progressChan <-chan progressMsg) error {
97-
model := NewProgessModel(*options)
97+
model := NewProgressModel(*options)
9898
program := tea.NewProgram(model, tea.WithContext(ctx))
9999

100100
go func() {
@@ -124,9 +124,9 @@ type progressMsg struct {
124124
type summaryResult string
125125

126126
const (
127-
resultConfimed = "confirmed"
128-
resultCanceled = "canceled"
129-
resultQuit = "quit"
127+
resultConfirmed = "confirmed"
128+
resultCanceled = "canceled"
129+
resultQuit = "quit"
130130
)
131131

132132
var _ tea.Model = &summaryModel{}
@@ -183,7 +183,7 @@ func (m *summaryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
183183
if msg.Type == tea.KeyEnter {
184184
// User has confirmed
185185
copy := *m
186-
copy.result = resultConfimed
186+
copy.result = resultConfirmed
187187
return &copy, tea.Quit
188188
}
189189
}
@@ -269,8 +269,8 @@ func (m *summaryModel) View() string {
269269

270270
var _ tea.Model = &progressModel{}
271271

272-
// NewProgessModel creates a new model for the initialization progress dialog shown during 'rad init'.
273-
func NewProgessModel(options initOptions) tea.Model {
272+
// NewProgressModel creates a new model for the initialization progress dialog shown during 'rad init'.
273+
func NewProgressModel(options initOptions) tea.Model {
274274
return &progressModel{
275275
options: options,
276276
spinner: spinner.New(spinner.WithSpinner(progressSpinner)),

pkg/cli/cmd/radinit/display_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func Test_summaryModel(t *testing.T) {
7171
}
7272

7373
t.Run("Result: Confirm", func(t *testing.T) {
74-
resultTest(t, resultConfimed, tea.KeyEnter)
74+
resultTest(t, resultConfirmed, tea.KeyEnter)
7575
})
7676

7777
t.Run("Result: Cancel", func(t *testing.T) {
@@ -104,7 +104,7 @@ func Test_summaryModel(t *testing.T) {
104104
// Please see: https://github.com/charmbracelet/x/blob/20117e9c8cd5ad229645f1bca3422b7e4110c96c/exp/teatest/teatest.go#L220.
105105
// That is why we call tm.Quit() before tm.FinalModel().
106106
model = tm.FinalModel(t).(*summaryModel)
107-
assert.Equal(t, summaryResult(resultConfimed), model.result)
107+
assert.Equal(t, summaryResult(resultConfirmed), model.result)
108108
}
109109

110110
t.Run("View: existing options", func(t *testing.T) {

pkg/cli/cmd/radinit/init_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func Test_Validate(t *testing.T) {
128128
// No application
129129
setScaffoldApplicationPromptNo(mocks.Prompter)
130130

131-
setConfirmOption(mocks.Prompter, resultConfimed)
131+
setConfirmOption(mocks.Prompter, resultConfirmed)
132132
},
133133
},
134134
{
@@ -159,7 +159,7 @@ func Test_Validate(t *testing.T) {
159159
// No application
160160
setScaffoldApplicationPromptNo(mocks.Prompter)
161161

162-
setConfirmOption(mocks.Prompter, resultConfimed)
162+
setConfirmOption(mocks.Prompter, resultConfirmed)
163163
},
164164
},
165165
{
@@ -194,7 +194,7 @@ func Test_Validate(t *testing.T) {
194194
// No application
195195
setScaffoldApplicationPromptNo(mocks.Prompter)
196196

197-
setConfirmOption(mocks.Prompter, resultConfimed)
197+
setConfirmOption(mocks.Prompter, resultConfirmed)
198198
},
199199
},
200200
{
@@ -224,7 +224,7 @@ func Test_Validate(t *testing.T) {
224224
// No application
225225
setScaffoldApplicationPromptNo(mocks.Prompter)
226226

227-
setConfirmOption(mocks.Prompter, resultConfimed)
227+
setConfirmOption(mocks.Prompter, resultConfirmed)
228228
},
229229
},
230230
{
@@ -264,7 +264,7 @@ func Test_Validate(t *testing.T) {
264264
// No application
265265
setScaffoldApplicationPromptNo(mocks.Prompter)
266266

267-
setConfirmOption(mocks.Prompter, resultConfimed)
267+
setConfirmOption(mocks.Prompter, resultConfirmed)
268268
},
269269
},
270270
{
@@ -299,7 +299,7 @@ func Test_Validate(t *testing.T) {
299299
// No application
300300
setScaffoldApplicationPromptNo(mocks.Prompter)
301301

302-
setConfirmOption(mocks.Prompter, resultConfimed)
302+
setConfirmOption(mocks.Prompter, resultConfirmed)
303303
},
304304
},
305305
{
@@ -334,7 +334,7 @@ func Test_Validate(t *testing.T) {
334334
// No application
335335
setScaffoldApplicationPromptNo(mocks.Prompter)
336336

337-
setConfirmOption(mocks.Prompter, resultConfimed)
337+
setConfirmOption(mocks.Prompter, resultConfirmed)
338338
},
339339
},
340340
{
@@ -369,7 +369,7 @@ func Test_Validate(t *testing.T) {
369369
// No application
370370
setScaffoldApplicationPromptNo(mocks.Prompter)
371371

372-
setConfirmOption(mocks.Prompter, resultConfimed)
372+
setConfirmOption(mocks.Prompter, resultConfirmed)
373373
},
374374
},
375375
{
@@ -404,7 +404,7 @@ func Test_Validate(t *testing.T) {
404404
// No application
405405
setScaffoldApplicationPromptNo(mocks.Prompter)
406406

407-
setConfirmOption(mocks.Prompter, resultConfimed)
407+
setConfirmOption(mocks.Prompter, resultConfirmed)
408408
},
409409
},
410410
{
@@ -436,7 +436,7 @@ func Test_Validate(t *testing.T) {
436436
setScaffoldApplicationPromptYes(mocks.Prompter)
437437
setApplicationNamePrompt(mocks.Prompter, "valid")
438438

439-
setConfirmOption(mocks.Prompter, resultConfimed)
439+
setConfirmOption(mocks.Prompter, resultConfirmed)
440440
},
441441
},
442442
{
@@ -650,7 +650,7 @@ func Test_Validate(t *testing.T) {
650650
// No application
651651
setScaffoldApplicationPromptNo(mocks.Prompter)
652652

653-
setConfirmOption(mocks.Prompter, resultConfimed)
653+
setConfirmOption(mocks.Prompter, resultConfirmed)
654654
},
655655
},
656656
{

pkg/cli/cmd/radinit/preview/display.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (r *Runner) confirmOptions(ctx context.Context, options *initOptions) (bool
7777
}
7878

7979
switch model.(*summaryModel).result {
80-
case resultConfimed:
80+
case resultConfirmed:
8181
return true, nil
8282
case resultCanceled:
8383
return false, nil
@@ -89,12 +89,23 @@ func (r *Runner) confirmOptions(ctx context.Context, options *initOptions) (bool
8989
}
9090

9191
func (r *Runner) showProgress(ctx context.Context, options *initOptions, progressChan <-chan progressMsg) error {
92-
model := NewProgessModel(*options)
92+
model := NewProgressModel(*options)
9393
program := tea.NewProgram(model, tea.WithContext(ctx))
9494

9595
go func() {
96-
for msg := range progressChan {
97-
program.Send(msg)
96+
for {
97+
select {
98+
case <-ctx.Done():
99+
program.Send(tea.Quit)
100+
return
101+
case msg, ok := <-progressChan:
102+
if !ok {
103+
program.Send(tea.Quit)
104+
return
105+
}
106+
107+
program.Send(msg)
108+
}
98109
}
99110

100111
program.Send(tea.Quit)
@@ -118,9 +129,9 @@ type progressMsg struct {
118129
type summaryResult string
119130

120131
const (
121-
resultConfimed = "confirmed"
122-
resultCanceled = "canceled"
123-
resultQuit = "quit"
132+
resultConfirmed = "confirmed"
133+
resultCanceled = "canceled"
134+
resultQuit = "quit"
124135
)
125136

126137
var _ tea.Model = &summaryModel{}
@@ -160,7 +171,7 @@ func (m *summaryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
160171
}
161172
if msg.Type == tea.KeyEnter {
162173
copy := *m
163-
copy.result = resultConfimed
174+
copy.result = resultConfirmed
164175
return &copy, tea.Quit
165176
}
166177
}
@@ -242,7 +253,7 @@ func (m *summaryModel) View() string {
242253

243254
var _ tea.Model = &progressModel{}
244255

245-
func NewProgessModel(options initOptions) tea.Model {
256+
func NewProgressModel(options initOptions) tea.Model {
246257
return &progressModel{
247258
options: options,
248259
spinner: spinner.New(spinner.WithSpinner(progressSpinner)),

pkg/cli/cmd/radinit/preview/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func (r *Runner) Run(ctx context.Context) error {
190190

191191
// Use this channel to send progress updates to the UI.
192192
progressChan := make(chan progressMsg)
193+
defer close(progressChan)
193194
progressCompleteChan := make(chan error)
194195
progress := progressMsg{}
195196

pkg/cli/cmd/radinit/preview/init_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func Test_Validate(t *testing.T) {
129129
// No application
130130
setScaffoldApplicationPromptNo(mocks.Prompter)
131131

132-
setConfirmOption(mocks.Prompter, resultConfimed)
132+
setConfirmOption(mocks.Prompter, resultConfirmed)
133133
},
134134
},
135135
{
@@ -160,7 +160,7 @@ func Test_Validate(t *testing.T) {
160160
// No application
161161
setScaffoldApplicationPromptNo(mocks.Prompter)
162162

163-
setConfirmOption(mocks.Prompter, resultConfimed)
163+
setConfirmOption(mocks.Prompter, resultConfirmed)
164164
},
165165
},
166166
{
@@ -196,7 +196,7 @@ func Test_Validate(t *testing.T) {
196196
// No application
197197
setScaffoldApplicationPromptNo(mocks.Prompter)
198198

199-
setConfirmOption(mocks.Prompter, resultConfimed)
199+
setConfirmOption(mocks.Prompter, resultConfirmed)
200200
},
201201
},
202202
{
@@ -227,7 +227,7 @@ func Test_Validate(t *testing.T) {
227227
// No application
228228
setScaffoldApplicationPromptNo(mocks.Prompter)
229229

230-
setConfirmOption(mocks.Prompter, resultConfimed)
230+
setConfirmOption(mocks.Prompter, resultConfirmed)
231231
},
232232
},
233233
{
@@ -258,7 +258,7 @@ func Test_Validate(t *testing.T) {
258258
// No application
259259
setScaffoldApplicationPromptNo(mocks.Prompter)
260260

261-
setConfirmOption(mocks.Prompter, resultConfimed)
261+
setConfirmOption(mocks.Prompter, resultConfirmed)
262262
},
263263
},
264264
{
@@ -293,7 +293,7 @@ func Test_Validate(t *testing.T) {
293293
// No application
294294
setScaffoldApplicationPromptNo(mocks.Prompter)
295295

296-
setConfirmOption(mocks.Prompter, resultConfimed)
296+
setConfirmOption(mocks.Prompter, resultConfirmed)
297297
},
298298
},
299299
{
@@ -328,7 +328,7 @@ func Test_Validate(t *testing.T) {
328328
// No application
329329
setScaffoldApplicationPromptNo(mocks.Prompter)
330330

331-
setConfirmOption(mocks.Prompter, resultConfimed)
331+
setConfirmOption(mocks.Prompter, resultConfirmed)
332332
},
333333
},
334334
{
@@ -363,7 +363,7 @@ func Test_Validate(t *testing.T) {
363363
// No application
364364
setScaffoldApplicationPromptNo(mocks.Prompter)
365365

366-
setConfirmOption(mocks.Prompter, resultConfimed)
366+
setConfirmOption(mocks.Prompter, resultConfirmed)
367367
},
368368
},
369369
{
@@ -398,7 +398,7 @@ func Test_Validate(t *testing.T) {
398398
// No application
399399
setScaffoldApplicationPromptNo(mocks.Prompter)
400400

401-
setConfirmOption(mocks.Prompter, resultConfimed)
401+
setConfirmOption(mocks.Prompter, resultConfirmed)
402402
},
403403
},
404404
{
@@ -431,7 +431,7 @@ func Test_Validate(t *testing.T) {
431431
setScaffoldApplicationPromptYes(mocks.Prompter)
432432
setApplicationNamePrompt(mocks.Prompter, "valid")
433433

434-
setConfirmOption(mocks.Prompter, resultConfimed)
434+
setConfirmOption(mocks.Prompter, resultConfirmed)
435435
},
436436
},
437437
{
@@ -649,7 +649,7 @@ func Test_Validate(t *testing.T) {
649649
// No application
650650
setScaffoldApplicationPromptNo(mocks.Prompter)
651651

652-
setConfirmOption(mocks.Prompter, resultConfimed)
652+
setConfirmOption(mocks.Prompter, resultConfirmed)
653653
},
654654
},
655655
{

0 commit comments

Comments
 (0)