Skip to content

Commit

Permalink
ps: --format {{.State}} match docker output
Browse files Browse the repository at this point in the history
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 containers#18244

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Apr 24, 2023
1 parent d05a980 commit 55d39c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
13 changes: 4 additions & 9 deletions cmd/podman/containers/ps.go
Expand Up @@ -351,8 +351,8 @@ func (l psReporter) Pod() string {
return l.ListContainer.Pod
}

// State returns the container state in human duration
func (l psReporter) State() string {
// Status is a synonym for State()
func (l psReporter) Status() string {
var state string
switch l.ListContainer.State {
case "running":
Expand All @@ -370,16 +370,11 @@ func (l psReporter) State() string {
//nolint:staticcheck
state = strings.Title(l.ListContainer.State)
}
return state
}

// Status is a synonym for State()
func (l psReporter) Status() string {
hc := l.ListContainer.Status
if hc != "" {
return l.State() + " (" + hc + ")"
state += " (" + hc + ")"
}
return l.State()
return state
}

func (l psReporter) RunningFor() string {
Expand Down
4 changes: 2 additions & 2 deletions test/system/040-ps.bats
Expand Up @@ -14,8 +14,8 @@ load helpers

# Special case: formatted ps
run_podman ps --no-trunc \
--format '{{.ID}} {{.Image}} {{.Command}} {{.Names}}'
is "$output" "$cid $IMAGE sleep 5 $rand_name" "podman ps"
--format '{{.ID}} {{.Image}} {{.Command}} {{.Names}} {{.State}}'
is "$output" "$cid $IMAGE sleep 5 $rand_name running" "podman ps"


# Plain old regular ps
Expand Down

0 comments on commit 55d39c3

Please sign in to comment.