convert from singular to Containers

Signed-off-by: Dowideit, Sven (O&A, St. Lucia) <Sven.Dowideit@csiro.au>
This commit is contained in:
Dowideit, Sven (O&A, St. Lucia) 2019-07-15 10:12:48 +10:00 committed by Sven Dowideit
parent 510b4b9ad6
commit 3a9152d681
4 changed files with 22 additions and 22 deletions

View file

@ -219,11 +219,11 @@ func (c *DockerCommand) RefreshContainersAndServices() error {
// sort services first by whether they have a linked container, and second by alphabetical order
sort.Slice(services, func(i, j int) bool {
if services[i].Container != nil && services[j].Container == nil {
if len(services[i].Containers) > 0 && len(services[j].Containers) == 0 {
return true
}
if services[i].Container == nil && services[j].Container != nil {
if len(services[i].Containers) == 0 && len(services[j].Containers) > 0 {
return false
}
@ -241,7 +241,7 @@ func (c *DockerCommand) assignContainersToServices(containers []*Container, serv
for _, service := range services {
for _, container := range containers {
if /*!container.OneOff &&*/ container.ServiceName == service.Name {
service.Container = append(service.Container, container)
service.Containers = append(service.Containers, container)
continue
}
}

View file

@ -17,24 +17,24 @@ type Service struct {
ID string
OSCommand *OSCommand
Log *logrus.Entry
Container []*Container
Containers []*Container
DockerCommand LimitedDockerCommand
}
// GetDisplayStrings returns the dispaly string of Container
func (s *Service) GetDisplayStrings(isFocused bool) []string {
if len(s.Container) == 0 {
if len(s.Containers) == 0 {
return []string{utils.ColoredString("none", color.FgBlue), s.Name, ""}
}
cont := s.Container[0]
cont := s.Containers[0]
return []string{cont.GetDisplayStatus(), s.Name, cont.GetDisplayCPUPerc()}
}
// Remove removes the service's containers
func (s *Service) Remove(options types.ContainerRemoveOptions) error {
return s.Container[0].Remove(options)
return s.Containers[0].Remove(options)
}
// Stop stops the service's containers
@ -59,12 +59,12 @@ func (s *Service) Restart() error {
// Attach attaches to the service
func (s *Service) Attach() (*exec.Cmd, error) {
return s.Container[0].Attach()
return s.Containers[0].Attach()
}
// Top returns process information
func (s *Service) Top() (container.ContainerTopOKBody, error) {
return s.Container[0].Top()
return s.Containers[0].Top()
}
// ViewLogs attaches to a subprocess viewing the service's logs

View file

@ -34,8 +34,8 @@ func (gui *Gui) refreshProject() error {
projectName := path.Base(gui.Config.ProjectDir)
if gui.DockerCommand.InDockerComposeProject {
for _, service := range gui.DockerCommand.Services {
if service.Container != nil {
projectName = service.Container[0].Details.Config.Labels["com.docker.compose.project"]
if len(service.Containers) > 0 {
projectName = service.Containers[0].Details.Config.Labels["com.docker.compose.project"]
break
}
}

View file

@ -46,8 +46,8 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error {
}
containerID := ""
if service.Container != nil {
containerID = service.Container[0].ID
if len(service.Containers) > 0 {
containerID = service.Containers[0].ID
}
if err := gui.focusPoint(0, gui.State.Panels.Services.SelectedLine, len(gui.DockerCommand.Services), v); err != nil {
@ -74,10 +74,10 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error {
return err
}
case "container-config":
if service.Container == nil {
if len(service.Containers) == 0 {
return gui.renderString(gui.g, "main", gui.Tr.NoContainer)
}
if err := gui.renderContainerConfig(service.Container[0]); err != nil {
if err := gui.renderContainerConfig(service.Containers[0]); err != nil {
return err
}
case "top":
@ -92,11 +92,11 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) renderServiceStats(service *commands.Service) error {
if len(service.Container) == 0 {
if len(service.Containers) == 0 {
return nil
}
return gui.renderContainerStats(service.Container[0])
return gui.renderContainerStats(service.Containers[0])
}
func (gui *Gui) renderServiceTop(service *commands.Service) error {
@ -120,13 +120,13 @@ func (gui *Gui) renderServiceLogs(service *commands.Service) error {
return nil
}
if len(service.Container) == 0 {
if len(service.Containers) == 0 {
return gui.T.NewTask(func(stop chan struct{}) {
gui.clearMainView()
})
}
return gui.renderContainerLogs(service.Container[0])
return gui.renderContainerLogs(service.Containers[0])
}
func (gui *Gui) handleServicesNextLine(g *gocui.Gui, v *gocui.View) error {
@ -252,7 +252,7 @@ func (gui *Gui) handleServiceAttach(g *gocui.Gui, v *gocui.View) error {
return nil
}
if service.Container == nil {
if len(service.Containers) == 0 {
return gui.createErrorPanel(gui.g, gui.Tr.NoContainers)
}
@ -374,7 +374,7 @@ func (gui *Gui) handleServicesCustomCommand(g *gocui.Gui, v *gocui.View) error {
commandObject := gui.DockerCommand.NewCommandObject(commands.CommandObject{
Service: service,
Container: service.Container[0],
Container: service.Containers[0],
})
var customCommands []config.CustomCommand
@ -396,7 +396,7 @@ L:
}
}
if service.Container != nil {
if len(service.Containers) > 0 {
customCommands = append(customCommands, gui.Config.UserConfig.CustomCommands.Containers...)
}