Add --format flag for docker plugin ls
This fix tries to address the enhancement discussed in 28735 to add `--format` for the output of `docker plugin ls`. This fix 1. Add `--format` and `--quiet` flags to `docker plugin ls` 2. Convert the current implementation to use `formatter`, consistent with other docker list commands. 3. Add `pluginsFormat` for config.json. Related docs has been updated. Several unit tests have been added to cover the changes. This fix is related to 28708 and 28735. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> Upstream-commit: 1c0d37fa7f04ade13e65aff74ea0495bb846d782 Component: engine
This commit is contained in:
@@ -401,3 +401,29 @@ func (s *DockerSuite) TestPluginIDPrefix(c *check.C) {
|
||||
c.Assert(out, checker.Not(checker.Contains), pName)
|
||||
c.Assert(out, checker.Not(checker.Contains), pTag)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginListDefaultFormat(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, Network, IsAmd64)
|
||||
|
||||
config, err := ioutil.TempDir("", "config-file-")
|
||||
c.Assert(err, check.IsNil)
|
||||
defer os.RemoveAll(config)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(config, "config.json"), []byte(`{"pluginsFormat": "raw"}`), 0644)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", pName)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
out, _ = dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", pNameWithTag)
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
// We expect the format to be in `raw + --no-trunc`
|
||||
expectedOutput := fmt.Sprintf(`plugin_id: %s
|
||||
name: %s
|
||||
description: A sample volume plugin for Docker
|
||||
enabled: true`, id, pNameWithTag)
|
||||
|
||||
out, _ = dockerCmd(c, "--config", config, "plugin", "ls", "--no-trunc")
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, expectedOutput)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user