mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-23 07:31:03 +00:00
support attaching to containers
This commit is contained in:
parent
9ad6181420
commit
cf8e1f0195
5 changed files with 35 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
|
@ -19,6 +20,7 @@ type Container struct {
|
||||||
Container types.Container
|
Container types.Container
|
||||||
DisplayString string
|
DisplayString string
|
||||||
Client *client.Client
|
Client *client.Client
|
||||||
|
OSCommand *OSCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDisplayStrings returns the dispaly string of Container
|
// GetDisplayStrings returns the dispaly string of Container
|
||||||
|
|
@ -74,3 +76,9 @@ func (c *Container) Stop() error {
|
||||||
func (c *Container) Restart() error {
|
func (c *Container) Restart() error {
|
||||||
return c.Client.ContainerRestart(context.Background(), c.ID, nil)
|
return c.Client.ContainerRestart(context.Background(), c.ID, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attach attaches the container
|
||||||
|
func (c *Container) Attach() *exec.Cmd {
|
||||||
|
cmd := c.OSCommand.PrepareSubProcess("docker", "attach", "--sig-proxy=false", c.ID)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ func (c *DockerCommand) GetContainers() ([]*Container, error) {
|
||||||
ServiceName: serviceName,
|
ServiceName: serviceName,
|
||||||
Container: container,
|
Container: container,
|
||||||
Client: c.Client,
|
Client: c.Client,
|
||||||
|
OSCommand: c.OSCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -384,3 +384,18 @@ func (gui *Gui) handleContainerRestart(g *gocui.Gui, v *gocui.View) error {
|
||||||
return gui.refreshContainers()
|
return gui.refreshContainers()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleContainerAttach(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
container, err := gui.getSelectedContainer(g)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
subProcess := container.Attach()
|
||||||
|
if subProcess != nil {
|
||||||
|
gui.SubProcess = subProcess
|
||||||
|
return gui.Errors.ErrSubProcess
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||||
Handler: gui.handleContainerRestart,
|
Handler: gui.handleContainerRestart,
|
||||||
Description: gui.Tr.SLocalize("restartContainer"),
|
Description: gui.Tr.SLocalize("restartContainer"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ViewName: "containers",
|
||||||
|
Key: 'a',
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleContainerAttach,
|
||||||
|
Description: gui.Tr.SLocalize("attachContainer"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add more views here
|
// TODO: add more views here
|
||||||
|
|
|
||||||
|
|
@ -806,5 +806,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
||||||
ID: "nextContext",
|
ID: "nextContext",
|
||||||
Other: "next context",
|
Other: "next context",
|
||||||
},
|
},
|
||||||
|
&i18n.Message{
|
||||||
|
ID: "attachContainer",
|
||||||
|
Other: "attach to container",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue