-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_stop.go
More file actions
48 lines (39 loc) · 1.1 KB
/
run_stop.go
File metadata and controls
48 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ui
import (
"context"
"errors"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/localstack/lstk/internal/config"
"github.com/localstack/lstk/internal/container"
"github.com/localstack/lstk/internal/output"
"github.com/localstack/lstk/internal/runtime"
)
func RunStop(parentCtx context.Context, rt runtime.Runtime, containers []config.ContainerConfig) error {
ctx, cancel := context.WithCancel(parentCtx)
defer cancel()
app := NewApp("", "", "", cancel, withoutHeader())
p := tea.NewProgram(app, tea.WithInput(os.Stdin), tea.WithOutput(os.Stdout))
runErrCh := make(chan error, 1)
go func() {
err := container.Stop(ctx, rt, output.NewTUISink(programSender{p: p}), containers)
runErrCh <- err
if err != nil && !errors.Is(err, context.Canceled) {
p.Send(runErrMsg{err: err})
return
}
p.Send(runDoneMsg{})
}()
model, err := p.Run()
if err != nil {
return err
}
if app, ok := model.(App); ok && app.Err() != nil {
return output.NewSilentError(app.Err())
}
runErr := <-runErrCh
if runErr != nil && !errors.Is(runErr, context.Canceled) {
return runErr
}
return nil
}