Skip to content
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

feat: add tag command #553

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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