Skip to content

Commit

Permalink
feat: add tag command
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Lorenzen <[email protected]>
  • Loading branch information
Jaxwood committed Jun 23, 2024
1 parent 06ab7b7 commit 34dc3e5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/commands/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"context"
"fmt"
"strings"

"github.com/docker/docker/api/types/image"
Expand Down Expand Up @@ -143,3 +144,8 @@ func (c *DockerCommand) PruneImages() error {
_, err := c.Client.ImagesPrune(context.Background(), filters.Args{})
return err
}

func (i *Image) String() string {
return fmt.Sprintf("%s:%s", i.Name, i.Tag)
}

6 changes: 4 additions & 2 deletions pkg/gui/confirmation_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ func (gui *Gui) getConfirmationPanelDimensions(wrap bool, prompt string) (int, i
height/2 + panelHeight/2
}

func (gui *Gui) createPromptPanel(title string, handleConfirm func(*gocui.Gui, *gocui.View) error) error {
func (gui *Gui) createPromptPanel(title string, prompt string, handleConfirm func(*gocui.Gui, *gocui.View) error) error {
gui.onNewPopupPanel()
err := gui.prepareConfirmationPanel(title, "")
err := gui.prepareConfirmationPanel(title, prompt)
if err != nil {
return err
}
gui.Views.Confirmation.Editable = true
gui.Views.Confirmation.SetContent(prompt)
gui.Views.Confirmation.SetCursor(len(prompt), 0)
return gui.setKeyBindings(gui.g, handleConfirm, nil)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (gui *Gui) openFile(filename string) error {
}

func (gui *Gui) handleCustomCommand(g *gocui.Gui, v *gocui.View) error {
return gui.createPromptPanel(gui.Tr.CustomCommandTitle, func(g *gocui.Gui, v *gocui.View) error {
return gui.createPromptPanel(gui.Tr.CustomCommandTitle, "", func(g *gocui.Gui, v *gocui.View) error {
command := gui.trimmedContent(v)
return gui.runSubprocess(gui.OSCommand.RunCustomCommand(command))
})
Expand Down
26 changes: 26 additions & 0 deletions pkg/gui/images_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,29 @@ func (gui *Gui) handleImagesBulkCommand(g *gocui.Gui, v *gocui.View) error {

return gui.createBulkCommandMenu(bulkCommands, commandObject)
}

func (gui *Gui) handleImagesTagCommand(g *gocui.Gui, v *gocui.View) error {
image, err := gui.Panels.Images.GetSelectedItem()
if err != nil {
return nil
}

return gui.createPromptPanel(gui.Tr.NewTagCommand, image.String(), func(g *gocui.Gui, v *gocui.View) error {
newTag := gui.trimmedContent(v)

var cmd string
// if the user has provided a tag with a colon, we assume they've provided a full tag
if strings.Contains(newTag, ":") {
cmd = "docker tag " + image.String() + " " + newTag
} else {
cmd = "docker tag " + image.String() + " " + image.Name + ":" + newTag
}

err := gui.runSubprocess(gui.OSCommand.RunCustomCommand(cmd))
if err != nil {
return gui.createErrorPanel(err.Error())
}

return gui.reloadImages()
})
}
7 changes: 7 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleImagesBulkCommand,
Description: gui.Tr.ViewBulkCommands,
},
{
ViewName: "images",
Key: 't',
Modifier: gocui.ModNone,
Handler: gui.handleImagesTagCommand,
Description: gui.Tr.ViewTagCommands,
},
{
ViewName: "volumes",
Key: 'c',
Expand Down
4 changes: 4 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ type TranslationSet struct {
ExecShell string
RunCustomCommand string
ViewBulkCommands string
ViewTagCommands string
NewTagCommand string
FilterList string
OpenInBrowser string
SortContainersByState string
Expand Down Expand Up @@ -206,6 +208,8 @@ func englishSet() TranslationSet {
ExecShell: "exec shell",
RunCustomCommand: "run predefined custom command",
ViewBulkCommands: "view bulk commands",
ViewTagCommands: "view tag commands",
NewTagCommand: "new tag",
FilterList: "filter list",
OpenInBrowser: "open in browser (first port is http)",
SortContainersByState: "sort containers by state",
Expand Down

0 comments on commit 34dc3e5

Please sign in to comment.