mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
more
This commit is contained in:
parent
7e45881dc3
commit
71f05ff80a
5 changed files with 32 additions and 23 deletions
|
|
@ -310,9 +310,6 @@ func (c *Container) GetColor() color.Attribute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustStopContainer tells us that we must stop the container before removing it
|
|
||||||
const MustStopContainer = iota
|
|
||||||
|
|
||||||
// Remove removes the container
|
// Remove removes the container
|
||||||
func (c *Container) Remove(options types.ContainerRemoveOptions) error {
|
func (c *Container) Remove(options types.ContainerRemoveOptions) error {
|
||||||
if err := c.Client.ContainerRemove(context.Background(), c.ID, options); err != nil {
|
if err := c.Client.ContainerRemove(context.Background(), c.ID, options); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,11 @@ import (
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// MustStopContainer tells us that we must stop the container before removing it
|
||||||
|
MustStopContainer = iota
|
||||||
|
)
|
||||||
|
|
||||||
// WrapError wraps an error for the sake of showing a stack trace at the top level
|
// WrapError wraps an error for the sake of showing a stack trace at the top level
|
||||||
// the go-errors package, for some reason, does not return nil when you try to wrap
|
// the go-errors package, for some reason, does not return nil when you try to wrap
|
||||||
// a non-error, so we're just doing it here
|
// a non-error, so we're just doing it here
|
||||||
|
|
@ -31,9 +36,19 @@ func (ce ComplexError) FormatError(p xerrors.Printer) error {
|
||||||
ce.frame.Format(p)
|
ce.frame.Format(p)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ce ComplexError) Format(f fmt.State, c rune) {
|
func (ce ComplexError) Format(f fmt.State, c rune) {
|
||||||
xerrors.FormatError(ce, f, c)
|
xerrors.FormatError(ce, f, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ce ComplexError) Error() string {
|
func (ce ComplexError) Error() string {
|
||||||
return fmt.Sprint(ce)
|
return fmt.Sprint(ce)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HasErrorCode(err error, code int) bool {
|
||||||
|
var originalErr ComplexError
|
||||||
|
if xerrors.As(err, &originalErr) {
|
||||||
|
return originalErr.Code == MustStopContainer
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,6 @@ func (s *Service) Restart() error {
|
||||||
|
|
||||||
// Attach attaches to the service
|
// Attach attaches to the service
|
||||||
func (s *Service) Attach() (*exec.Cmd, error) {
|
func (s *Service) Attach() (*exec.Cmd, error) {
|
||||||
// TODO: if you have a custom command for attaching to a service here is the place to use it
|
|
||||||
|
|
||||||
return s.Container.Attach()
|
return s.Container.Attach()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/commands"
|
"github.com/jesseduffield/lazydocker/pkg/commands"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/utils"
|
"github.com/jesseduffield/lazydocker/pkg/utils"
|
||||||
"golang.org/x/xerrors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// list panel functions
|
// list panel functions
|
||||||
|
|
@ -423,25 +422,20 @@ func (gui *Gui) handleContainersRemoveMenu(g *gocui.Gui, v *gocui.View) error {
|
||||||
configOptions := options[index].configOptions
|
configOptions := options[index].configOptions
|
||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.RemovingStatus, func() error {
|
return gui.WithWaitingStatus(gui.Tr.RemovingStatus, func() error {
|
||||||
if cerr := container.Remove(configOptions); cerr != nil {
|
if err := container.Remove(configOptions); err != nil {
|
||||||
var originalErr commands.ComplexError
|
if commands.HasErrorCode(err, commands.MustStopContainer) {
|
||||||
if xerrors.As(cerr, &originalErr) {
|
return gui.createConfirmationPanel(gui.g, v, gui.Tr.Confirm, gui.Tr.MustForceToRemoveContainer, func(g *gocui.Gui, v *gocui.View) error {
|
||||||
if originalErr.Code == commands.MustStopContainer {
|
return gui.WithWaitingStatus(gui.Tr.RemovingStatus, func() error {
|
||||||
return gui.createConfirmationPanel(gui.g, v, gui.Tr.Confirm, gui.Tr.MustForceToRemoveContainer, func(g *gocui.Gui, v *gocui.View) error {
|
configOptions.Force = true
|
||||||
return gui.WithWaitingStatus(gui.Tr.RemovingStatus, func() error {
|
if err := container.Remove(configOptions); err != nil {
|
||||||
configOptions.Force = true
|
return err
|
||||||
if err := container.Remove(configOptions); err != nil {
|
}
|
||||||
return err
|
return gui.refreshContainersAndServices()
|
||||||
}
|
})
|
||||||
return gui.refreshContainersAndServices()
|
}, nil)
|
||||||
})
|
|
||||||
}, nil)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return gui.createErrorPanel(gui.g, cerr.Error())
|
|
||||||
}
|
}
|
||||||
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.refreshContainersAndServices()
|
return gui.refreshContainersAndServices()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,12 @@ func (gui *Gui) handleServiceAttach(g *gocui.Gui, v *gocui.View) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if service.Container == nil {
|
||||||
|
return gui.createErrorPanel(gui.g, gui.Tr.NoContainers)
|
||||||
|
}
|
||||||
|
|
||||||
c, err := service.Attach()
|
c, err := service.Attach()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue