-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate stop command to output event system #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,27 +4,30 @@ import ( | |||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| "github.com/containerd/errdefs" | ||||||||||||||||||||||||
| "github.com/localstack/lstk/internal/config" | ||||||||||||||||||||||||
| "github.com/localstack/lstk/internal/output" | ||||||||||||||||||||||||
| "github.com/localstack/lstk/internal/runtime" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| func Stop(ctx context.Context, rt runtime.Runtime, onProgress func(string)) error { | ||||||||||||||||||||||||
| func Stop(ctx context.Context, rt runtime.Runtime, sink output.Sink) error { | ||||||||||||||||||||||||
| cfg, err := config.Get() | ||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||
| return fmt.Errorf("failed to get config: %w", err) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for _, c := range cfg.Containers { | ||||||||||||||||||||||||
| name := c.Name() | ||||||||||||||||||||||||
| onProgress(fmt.Sprintf("Stopping %s...", name)) | ||||||||||||||||||||||||
| running, err := rt.IsRunning(ctx, name) | ||||||||||||||||||||||||
| if err != nil || !running { | ||||||||||||||||||||||||
| return fmt.Errorf("%s is not running", name) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve At Line 21, 💡 Suggested fix running, err := rt.IsRunning(ctx, name)
- if err != nil || !running {
+ if err != nil {
+ return fmt.Errorf("failed to check %s status: %w", name, err)
+ }
+ if !running {
return fmt.Errorf("%s is not running", name)
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| output.EmitSpinnerStart(sink, fmt.Sprintf("Stopping %s", name)) | ||||||||||||||||||||||||
| if err := rt.Stop(ctx, name); err != nil { | ||||||||||||||||||||||||
| if errdefs.IsNotFound(err) { | ||||||||||||||||||||||||
| return fmt.Errorf("%s is not running", name) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| output.EmitSpinnerStop(sink) | ||||||||||||||||||||||||
| return fmt.Errorf("failed to stop %s: %w", name, err) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| onProgress(fmt.Sprintf("%s stopped", name)) | ||||||||||||||||||||||||
| output.EmitSpinnerStop(sink) | ||||||||||||||||||||||||
| output.EmitSuccess(sink, fmt.Sprintf("%s stopped", name)) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package ui | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "os" | ||
|
|
||
| tea "github.com/charmbracelet/bubbletea" | ||
| "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) error { | ||
| _, cancel := context.WithCancel(parentCtx) | ||
| defer cancel() | ||
|
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cancellation context is created but not used by the stop workflow. Line 15 creates a derived cancelable context, but Line 23 still passes 💡 Suggested fix-func RunStop(parentCtx context.Context, rt runtime.Runtime) error {
- _, cancel := context.WithCancel(parentCtx)
+func RunStop(parentCtx context.Context, rt runtime.Runtime) error {
+ runCtx, cancel := context.WithCancel(parentCtx)
defer cancel()
@@
go func() {
- err := container.Stop(parentCtx, rt, output.NewTUISink(programSender{p: p}))
+ err := container.Stop(runCtx, rt, output.NewTUISink(programSender{p: p}))
runErrCh <- errAlso applies to: 23-23, 41-44 🤖 Prompt for AI Agents |
||
|
|
||
| app := NewApp("", "", "", cancel) | ||
| p := tea.NewProgram(app, tea.WithInput(os.Stdin), tea.WithOutput(os.Stdout)) | ||
| runErrCh := make(chan error, 1) | ||
|
|
||
| go func() { | ||
| err := container.Stop(parentCtx, rt, output.NewTUISink(programSender{p: p})) | ||
| 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 app.Err() | ||
| } | ||
|
|
||
| runErr := <-runErrCh | ||
| if runErr != nil && !errors.Is(runErr, context.Canceled) { | ||
| return runErr | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build blocker:
rootCmdis undefined in this package.Line 44 currently fails compilation (
undefined: rootCmd) per CI. Register this command through the actual root-command symbol/mechanism used incmd(or restore the prior registration path).🧰 Tools
🪛 GitHub Actions: LSTK CI
[error] 44-44: go build -o bin/lstk.exe . failed: undefined: rootCmd (undefined: rootCmd) in cmd/stop.go:44
🪛 GitHub Check: Integration Tests (macos-latest)
[failure] 44-44:
undefined: rootCmd
🪛 GitHub Check: Integration Tests (ubuntu-latest)
[failure] 44-44:
undefined: rootCmd
🪛 GitHub Check: Integration Tests (windows-latest)
[failure] 44-44:
undefined: rootCmd
🪛 GitHub Check: Lint
[failure] 44-44:
undefined: rootCmd) (typecheck)
🪛 GitHub Check: Unit Tests
[failure] 44-44:
undefined: rootCmd
🤖 Prompt for AI Agents