mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
fix up rebuild container logic
This commit is contained in:
parent
3bcef6d88c
commit
9a5a01dfbd
2 changed files with 25 additions and 24 deletions
|
|
@ -207,7 +207,9 @@ func (gui *Gui) renderLogs(container *commands.Container, template string, setup
|
||||||
default:
|
default:
|
||||||
result, err := gui.DockerCommand.Client.ContainerInspect(context.Background(), container.ID)
|
result, err := gui.DockerCommand.Client.ContainerInspect(context.Background(), container.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// if we get an error, then the container has probably been removed so we'll get out of here
|
||||||
gui.Log.Error(err)
|
gui.Log.Error(err)
|
||||||
|
notifyStopped <- struct{}{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if result.State.Running {
|
if result.State.Running {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
|
@ -187,6 +185,7 @@ func (gui *Gui) handleServicesNextContext(g *gocui.Gui, v *gocui.View) error {
|
||||||
type commandOption struct {
|
type commandOption struct {
|
||||||
description string
|
description string
|
||||||
command string
|
command string
|
||||||
|
f func() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDisplayStrings is a function.
|
// GetDisplayStrings is a function.
|
||||||
|
|
@ -293,50 +292,50 @@ func (gui *Gui) handleServiceRestartMenu(g *gocui.Gui, v *gocui.View) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rebuildCommand := utils.ApplyTemplate(gui.Config.UserConfig.CommandTemplates.RebuildService, service)
|
||||||
|
|
||||||
options := []*commandOption{
|
options := []*commandOption{
|
||||||
{
|
{
|
||||||
description: gui.Tr.Restart,
|
description: gui.Tr.Restart,
|
||||||
command: utils.ApplyTemplate(gui.Config.UserConfig.CommandTemplates.RestartService, service),
|
command: utils.ApplyTemplate(gui.Config.UserConfig.CommandTemplates.RestartService, service),
|
||||||
|
f: func() error {
|
||||||
|
return gui.WithWaitingStatus(gui.Tr.RestartingStatus, func() error {
|
||||||
|
if err := service.Restart(); err != nil {
|
||||||
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.refreshContainersAndServices()
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: gui.Tr.Rebuild,
|
description: gui.Tr.Rebuild,
|
||||||
command: utils.ApplyTemplate(gui.Config.UserConfig.CommandTemplates.RebuildService, service),
|
command: utils.ApplyTemplate(gui.Config.UserConfig.CommandTemplates.RebuildService, service),
|
||||||
|
f: func() error {
|
||||||
|
gui.SubProcess = gui.OSCommand.RunCustomCommand(rebuildCommand)
|
||||||
|
return gui.Errors.ErrSubProcess
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: gui.Tr.Cancel,
|
description: gui.Tr.Cancel,
|
||||||
|
f: func() error { return nil },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.createCommandMenu(options, gui.Tr.RestartingStatus)
|
handleMenuPress := func(index int) error { return options[index].f() }
|
||||||
|
|
||||||
|
return gui.createMenu("", options, len(options), handleMenuPress)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) createCommandMenu(options []*commandOption, status string) error {
|
func (gui *Gui) createCommandMenu(options []*commandOption, status string) error {
|
||||||
|
|
||||||
handleMenuPress := func(index int) error {
|
handleMenuPress := func(index int) error {
|
||||||
if options[index].command == "" {
|
if options[index].command == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
gui.getMainView().Clear()
|
|
||||||
return gui.WithWaitingStatus(status, func() error {
|
return gui.WithWaitingStatus(status, func() error {
|
||||||
done := make(chan struct{})
|
if err := gui.OSCommand.RunCommand(options[index].command); err != nil {
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
cmd := gui.OSCommand.RunCustomCommand(options[index].command)
|
}
|
||||||
|
|
||||||
cmd.Stdout = gui.getMainView()
|
|
||||||
var stderrBuf bytes.Buffer
|
|
||||||
cmd.Stderr = io.MultiWriter(gui.getMainView(), &stderrBuf)
|
|
||||||
|
|
||||||
cmd.Run()
|
|
||||||
|
|
||||||
close(done)
|
|
||||||
|
|
||||||
errorMessage := stderrBuf.String()
|
|
||||||
if errorMessage != "" {
|
|
||||||
gui.createErrorPanel(gui.g, errorMessage)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
<-done
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue