ps: --format {{.State}} match docker output

We should return the raw state string without any extra formatting in
this case.
`{{.Status}}` returns the nicely formatted string used in the default ps
output, e.g. `Up 2 seconds ago`, while `{{.State}}` returns the state as
string, e.g. `running`.

This matches the docker output and allows better use in scripts.

Fixes #18244

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2023-04-24 14:13:41 +02:00
parent d05a980792
commit c5a928c5b7
No known key found for this signature in database
GPG Key ID: EB145DD938A3CAF2
2 changed files with 6 additions and 11 deletions

View File

@ -351,8 +351,8 @@ func (l psReporter) Pod() string {
return l.ListContainer.Pod return l.ListContainer.Pod
} }
// State returns the container state in human duration // Status returns the container status in the default ps output format.
func (l psReporter) State() string { func (l psReporter) Status() string {
var state string var state string
switch l.ListContainer.State { switch l.ListContainer.State {
case "running": case "running":
@ -370,16 +370,11 @@ func (l psReporter) State() string {
//nolint:staticcheck //nolint:staticcheck
state = strings.Title(l.ListContainer.State) state = strings.Title(l.ListContainer.State)
} }
return state
}
// Status is a synonym for State()
func (l psReporter) Status() string {
hc := l.ListContainer.Status hc := l.ListContainer.Status
if hc != "" { if hc != "" {
return l.State() + " (" + hc + ")" state += " (" + hc + ")"
} }
return l.State() return state
} }
func (l psReporter) RunningFor() string { func (l psReporter) RunningFor() string {

View File

@ -14,8 +14,8 @@ load helpers
# Special case: formatted ps # Special case: formatted ps
run_podman ps --no-trunc \ run_podman ps --no-trunc \
--format '{{.ID}} {{.Image}} {{.Command}} {{.Names}}' --format '{{.ID}} {{.Image}} {{.Command}} {{.Names}} {{.State}}'
is "$output" "$cid $IMAGE sleep 5 $rand_name" "podman ps" is "$output" "$cid $IMAGE sleep 5 $rand_name running" "podman ps"
# Plain old regular ps # Plain old regular ps