fix(ps): honor psFormat from Docker CLI config when no --format flag … · docker/compose@3a62ae6 · GitHub
Skip to content

Commit 3a62ae6

Browse files
gloursndeloof
authored andcommitted
fix(ps): honor psFormat from Docker CLI config when no --format flag given
The --format flag defaulted to "table" instead of "", so the opts.Format == "" guard in runPs never fired for a bare compose ps. Setting the default to "" lets the existing config-fallback path work, matching the behaviour of docker ps. Fixes #13643 Supersedes #14032 Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
1 parent c594d34 commit 3a62ae6

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎cmd/compose/ps.go‎

Lines changed: 1 addition & 1 deletion

‎docs/reference/compose_ps.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ example-bar-1 alpine "/entrypoint.…" bar 4 seconds ago exited
2525
| `-a`, `--all` | `bool` | | Show all stopped containers (including those created by the run command) |
2626
| `--dry-run` | `bool` | | Execute command in dry run mode |
2727
| [`--filter`](#filter) | `string` | | Filter services by a property (supported filters: status) |
28-
| [`--format`](#format) | `string` | `table` | Format output using a custom template:<br>'table': Print output in table format with column headers (default)<br>'table TEMPLATE': Print output in table format using the given Go template<br>'json': Print in JSON format<br>'TEMPLATE': Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
28+
| [`--format`](#format) | `string` | | Format output using a custom template:<br>'table': Print output in table format with column headers (default)<br>'table TEMPLATE': Print output in table format using the given Go template<br>'json': Print in JSON format<br>'TEMPLATE': Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
2929
| `--no-trunc` | `bool` | | Don't truncate output |
3030
| `--orphans` | `bool` | `true` | Include orphaned services (not declared by project) |
3131
| `-q`, `--quiet` | `bool` | | Only display IDs |

‎docs/reference/docker_compose_ps.yaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ options:
4545
swarm: false
4646
- option: format
4747
value_type: string
48-
default_value: table
4948
description: |-
5049
Format output using a custom template:
5150
'table': Print output in table format with column headers (default)

‎pkg/e2e/ps_test.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ package e2e
1818

1919
import (
2020
"encoding/json"
21+
"os"
22+
"path/filepath"
2123
"strings"
2224
"testing"
25+
"time"
2326

2427
"gotest.tools/v3/assert"
2528
is "gotest.tools/v3/assert/cmp"
@@ -133,3 +136,22 @@ func TestPs(t *testing.T) {
133136
res.Assert(t, icmd.Expected{ExitCode: 1, Err: "no such service: unknown"})
134137
})
135138
}
139+
140+
// #13643: compose ps did not honor psFormat from Docker config when no
141+
// --format flag was given; the flag defaulted to "table", preventing the
142+
// empty-string check from firing.
143+
func TestPsHonorsPsFormat(t *testing.T) {
144+
s := NewScenario(t, "compose ps must apply psFormat from Docker CLI config when no --format flag is given")
145+
// Write psFormat into the CLI's config dir, which already holds the
146+
// test-built compose binary in cli-plugins/. Redirecting DOCKER_CONFIG
147+
// via s.Env() to a separate directory would strip those plugins, causing
148+
// docker compose to fall back to the system binary that predates the fix.
149+
assert.NilError(t, os.WriteFile(filepath.Join(s.CLI().ConfigDir, "config.json"), []byte(`{"psFormat":"table {{.Name}}"}`), 0o600))
150+
s.Step("service starts",
151+
ComposeCmd("up", "-d"),
152+
Eventually(ServiceState("app", "running"), 10*time.Second)).
153+
Step("ps without --format renders only the NAME column from psFormat",
154+
ComposeCmd("ps"),
155+
OutputContains("NAME"),
156+
OutputNotContains("IMAGE"))
157+
}
Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)