|
|
|
@ -4,6 +4,8 @@ import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
|
"github.com/go-errors/errors"
|
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
|
"github.com/jesseduffield/lazydocker/pkg/commands"
|
|
|
|
@ -206,67 +208,66 @@ func (gui *Gui) handleImagesNextContext(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// type removeOption struct {
|
|
|
|
|
// description string
|
|
|
|
|
// command string
|
|
|
|
|
// configOptions types.ImageRemoveOptions
|
|
|
|
|
// runCommand bool
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // GetDisplayStrings is a function.
|
|
|
|
|
// func (r *removeOption) GetDisplayStrings(isFocused bool) []string {
|
|
|
|
|
// return []string{r.description, color.New(color.FgRed).Sprint(r.command)}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// func (gui *Gui) handleImagesRemoveMenu(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
// Image, err := gui.getSelectedImage(g)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// return nil
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// options := []*removeOption{
|
|
|
|
|
// {
|
|
|
|
|
// description: gui.Tr.SLocalize("remove"),
|
|
|
|
|
// command: "docker rm " + Image.ID[1:10],
|
|
|
|
|
// configOptions: types.ImageRemoveOptions{},
|
|
|
|
|
// runCommand: true,
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// description: gui.Tr.SLocalize("removeWithVolumes"),
|
|
|
|
|
// command: "docker rm --volumes " + Image.ID[1:10],
|
|
|
|
|
// configOptions: types.ImageRemoveOptions{RemoveVolumes: true},
|
|
|
|
|
// runCommand: true,
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// description: gui.Tr.SLocalize("cancel"),
|
|
|
|
|
// runCommand: false,
|
|
|
|
|
// },
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// handleMenuPress := func(index int) error {
|
|
|
|
|
// if !options[index].runCommand {
|
|
|
|
|
// return nil
|
|
|
|
|
// }
|
|
|
|
|
// configOptions := options[index].configOptions
|
|
|
|
|
// if cerr := Image.Remove(configOptions); cerr != nil {
|
|
|
|
|
// var originalErr commands.ComplexError
|
|
|
|
|
// if xerrors.As(cerr, &originalErr) {
|
|
|
|
|
// if originalErr.Code == commands.MustStopImage {
|
|
|
|
|
// return gui.createConfirmationPanel(gui.g, v, gui.Tr.SLocalize("Confirm"), gui.Tr.SLocalize("mustForceToRemove"), func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
// configOptions.Force = true
|
|
|
|
|
// if err := Image.Remove(configOptions); err != nil {
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// return gui.refreshImages()
|
|
|
|
|
// }, nil)
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// return gui.createErrorPanel(gui.g, err.Error())
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return gui.refreshImages()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return gui.createMenu("", options, len(options), handleMenuPress)
|
|
|
|
|
// }
|
|
|
|
|
type removeImageOption struct {
|
|
|
|
|
description string
|
|
|
|
|
command string
|
|
|
|
|
configOptions types.ImageRemoveOptions
|
|
|
|
|
runCommand bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetDisplayStrings is a function.
|
|
|
|
|
func (r *removeImageOption) GetDisplayStrings(isFocused bool) []string {
|
|
|
|
|
return []string{r.description, color.New(color.FgRed).Sprint(r.command)}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gui *Gui) handleImagesRemoveMenu(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
Image, err := gui.getSelectedImage(g)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options := []*removeImageOption{
|
|
|
|
|
{
|
|
|
|
|
description: gui.Tr.SLocalize("remove"),
|
|
|
|
|
command: "docker image rm " + Image.ID[1:20],
|
|
|
|
|
configOptions: types.ImageRemoveOptions{PruneChildren: true},
|
|
|
|
|
runCommand: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
description: gui.Tr.SLocalize("removeWithoutPrune"),
|
|
|
|
|
command: "docker image rm --no-prune " + Image.ID[1:20],
|
|
|
|
|
configOptions: types.ImageRemoveOptions{PruneChildren: false},
|
|
|
|
|
runCommand: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
description: gui.Tr.SLocalize("cancel"),
|
|
|
|
|
runCommand: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleMenuPress := func(index int) error {
|
|
|
|
|
if !options[index].runCommand {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
configOptions := options[index].configOptions
|
|
|
|
|
if cerr := Image.Remove(configOptions); cerr != nil {
|
|
|
|
|
return gui.createErrorPanel(gui.g, cerr.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gui.refreshImages()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gui.createMenu("", options, len(options), handleMenuPress)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gui *Gui) handlePruneImages(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
return gui.createConfirmationPanel(gui.g, v, gui.Tr.SLocalize("Confirm"), gui.Tr.SLocalize("confirmPruneImages"), func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
return gui.WithWaitingStatus(gui.Tr.SLocalize("PruningStatus"), func() error {
|
|
|
|
|
err := gui.DockerCommand.PruneImages()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return gui.createErrorPanel(gui.g, err.Error())
|
|
|
|
|
}
|
|
|
|
|
return gui.refreshImages()
|
|
|
|
|
})
|
|
|
|
|
}, nil)
|
|
|
|
|
}
|
|
|
|
|