This fix tries to fix the issue in 30279 where `docker ps --format`
fails if `.Label` has args. For example:
```
docker ps --format '{{.ID}}\t{{.Names}}\t{{.Label "some.label"}}'
```
The reason for the failure is that during the preprocessing phase
to detect the existance of `.Size`, the `listOptionsProcessor`
does not has a method of `Label(name string) string`.
This results in the failure of
```
template: :1:24: executing "" at <.Label>: Label is not a method but has arguments
```
This fix fixes the issue by adding needed method of `Label(name string) string`.
This fix fixes 30279.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
... | ... |
@@ -73,6 +73,12 @@ func (o listOptionsProcessor) Size() bool { |
73 | 73 |
return true |
74 | 74 |
} |
75 | 75 |
|
76 |
+// Label is needed here as it allows the correct pre-processing |
|
77 |
+// because Label() is a method with arguments |
|
78 |
+func (o listOptionsProcessor) Label(name string) string { |
|
79 |
+ return "" |
|
80 |
+} |
|
81 |
+ |
|
76 | 82 |
func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, error) { |
77 | 83 |
options := &types.ContainerListOptions{ |
78 | 84 |
All: opts.all, |
... | ... |
@@ -917,3 +917,10 @@ func (s *DockerSuite) TestPsFilterMissingArgErrorCode(c *check.C) { |
917 | 917 |
_, errCode, _ := dockerCmdWithError("ps", "--filter") |
918 | 918 |
c.Assert(errCode, checker.Equals, 125) |
919 | 919 |
} |
920 |
+ |
|
921 |
+// Test case for 30291 |
|
922 |
+func (s *DockerSuite) TestPsFormatTemplateWithArg(c *check.C) { |
|
923 |
+ runSleepingContainer(c, "-d", "--name", "top", "--label", "some.label=label.foo-bar") |
|
924 |
+ out, _ := dockerCmd(c, "ps", "--format", `{{.Names}} {{.Label "some.label"}}`) |
|
925 |
+ c.Assert(strings.TrimSpace(out), checker.Equals, "top label.foo-bar") |
|
926 |
+} |