1
0
mirror of https://github.com/pcvolkmer/docker-pps.git synced 2025-04-19 17:56:50 +00:00

Extract method to get running processes

This commit is contained in:
Paul-Christian Volkmer 2022-12-21 20:09:40 +01:00
parent d7b61a9e5d
commit 1be4efc450

19
main.go
View File

@ -59,6 +59,17 @@ func main() {
return return
} }
if processes, err := getProcesses(dc); err == nil {
if *q == true {
printQuietTable(processes)
return
}
printTable(processes)
}
}
// Get all processes running in docker containers
func getProcesses(dc *client.Client) ([]Process, error) {
var processes []Process var processes []Process
if containers, err := dc.ContainerList(context.Background(), types.ContainerListOptions{All: true}); err == nil { if containers, err := dc.ContainerList(context.Background(), types.ContainerListOptions{All: true}); err == nil {
@ -94,14 +105,10 @@ func main() {
} }
} }
} else { } else {
log.Fatalln(err) return nil, err
} }
if *q == true { return processes, nil
printQuietTable(processes)
return
}
printTable(processes)
} }
// Print out table if processes, running within docker containers // Print out table if processes, running within docker containers