Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON output field for ps #6731

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ func checkFlags(c *cobra.Command) error {
}

func jsonOut(responses []entities.ListContainer) error {
b, err := json.MarshalIndent(responses, "", " ")
r := make([]entities.ListContainer, 0)
for _, con := range responses {
con.CreatedAt = units.HumanDuration(time.Since(time.Unix(con.Created, 0))) + " ago"
r = append(r, con)
}
b, err := json.MarshalIndent(r, "", " ")
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/entities/container_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type ListContainer struct {
Command []string
// Container creation time
Created int64
// Human readable container creation time.
CreatedAt string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to point out that the Created and CreatedAt fields are switched between ps and images.

In images, Created is the human-friendly string while CreatedAt is the machine-readable form. In ps, they are the other way round.

I don't really mind it. Just wanted to be sure that it's a deliberate decision (for Docker compatibility?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if they are switched in Docker as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker does not offer a JSON-formatted output.

// If container has exited/stopped
Exited bool
// Time container exited
Expand Down