diff --git a/cli/app/ps.go b/cli/app/ps.go index 5cb3adb2..1e88302a 100644 --- a/cli/app/ps.go +++ b/cli/app/ps.go @@ -63,14 +63,14 @@ var appPsCommand = cli.Command{ } if !internal.Watch { - showPSOutput(c, app, cl) + showPSOutput(app, cl) return nil } goterm.Clear() for { goterm.MoveCursor(1, 1) - showPSOutput(c, app, cl) + showPSOutput(app, cl) goterm.Flush() time.Sleep(2 * time.Second) } @@ -78,7 +78,7 @@ var appPsCommand = cli.Command{ } // showPSOutput renders ps output. -func showPSOutput(c *cli.Context, app appPkg.App, cl *dockerClient.Client) { +func showPSOutput(app appPkg.App, cl *dockerClient.Client) { composeFiles, err := recipe.GetComposeFiles(app.Recipe, app.Env) if err != nil { logrus.Fatal(err) @@ -110,7 +110,6 @@ func showPSOutput(c *cli.Context, app appPkg.App, cl *dockerClient.Client) { } var containerStats map[string]string - if len(containers) == 0 { containerStats = map[string]string{ "service name": service.Name, @@ -131,25 +130,36 @@ func showPSOutput(c *cli.Context, app appPkg.App, cl *dockerClient.Client) { "ports": dockerFormatter.DisplayablePorts(container.Ports), } } + allContainerStats[containerStats["service name"]] = containerStats - var tablerow []string = []string{containerStats["service name"], containerStats["image"], containerStats["created"], containerStats["status"], containerStats["state"], containerStats["ports"]} + tablerow := []string{ + containerStats["service name"], + containerStats["image"], + containerStats["created"], + containerStats["status"], + containerStats["state"], + containerStats["ports"], + } + tablerows = append(tablerows, tablerow) } + if internal.MachineReadable { jsonstring, err := json.Marshal(allContainerStats) if err != nil { logrus.Fatal(err) - } else { - fmt.Println(string(jsonstring)) } + + fmt.Println(string(jsonstring)) + return - } else { - tableCol := []string{"service name", "image", "created", "status", "state", "ports"} - table := formatter.CreateTable(tableCol) - for _, row := range tablerows { - table.Append(row) - } - table.Render() } + + tableCol := []string{"service name", "image", "created", "status", "state", "ports"} + table := formatter.CreateTable(tableCol) + for _, row := range tablerows { + table.Append(row) + } + table.Render() }