chore: formatting

This commit is contained in:
decentral1se 2024-07-07 22:40:06 +02:00
parent a001be3021
commit 6ec678208f
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410

View File

@ -63,14 +63,14 @@ var appPsCommand = cli.Command{
} }
if !internal.Watch { if !internal.Watch {
showPSOutput(c, app, cl) showPSOutput(app, cl)
return nil return nil
} }
goterm.Clear() goterm.Clear()
for { for {
goterm.MoveCursor(1, 1) goterm.MoveCursor(1, 1)
showPSOutput(c, app, cl) showPSOutput(app, cl)
goterm.Flush() goterm.Flush()
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
} }
@ -78,7 +78,7 @@ var appPsCommand = cli.Command{
} }
// showPSOutput renders ps output. // 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) composeFiles, err := recipe.GetComposeFiles(app.Recipe, app.Env)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
@ -110,7 +110,6 @@ func showPSOutput(c *cli.Context, app appPkg.App, cl *dockerClient.Client) {
} }
var containerStats map[string]string var containerStats map[string]string
if len(containers) == 0 { if len(containers) == 0 {
containerStats = map[string]string{ containerStats = map[string]string{
"service name": service.Name, "service name": service.Name,
@ -131,25 +130,36 @@ func showPSOutput(c *cli.Context, app appPkg.App, cl *dockerClient.Client) {
"ports": dockerFormatter.DisplayablePorts(container.Ports), "ports": dockerFormatter.DisplayablePorts(container.Ports),
} }
} }
allContainerStats[containerStats["service name"]] = containerStats 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) tablerows = append(tablerows, tablerow)
} }
if internal.MachineReadable { if internal.MachineReadable {
jsonstring, err := json.Marshal(allContainerStats) jsonstring, err := json.Marshal(allContainerStats)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} else {
fmt.Println(string(jsonstring))
} }
fmt.Println(string(jsonstring))
return 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()
} }