Ensure plugins default search path obeys `--config`

A static global initialiser happens before the arguments are parsed, so we need
to calculate the path later.

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell 2019-01-29 09:28:43 +00:00
parent 935d47bbe9
commit 0a89eb554b
2 changed files with 3 additions and 4 deletions

View File

@ -29,15 +29,13 @@ func IsNotFound(err error) bool {
return ok
}
var defaultUserPluginDir = config.Path("cli-plugins")
func getPluginDirs(dockerCli command.Cli) []string {
var pluginDirs []string
if cfg := dockerCli.ConfigFile(); cfg != nil {
pluginDirs = append(pluginDirs, cfg.CLIPluginsExtraDirs...)
}
pluginDirs = append(pluginDirs, defaultUserPluginDir)
pluginDirs = append(pluginDirs, config.Path("cli-plugins"))
pluginDirs = append(pluginDirs, defaultSystemPluginDirs...)
return pluginDirs
}

View File

@ -4,6 +4,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/internal/test"
"gotest.tools/assert"
@ -91,7 +92,7 @@ func TestErrPluginNotFound(t *testing.T) {
func TestGetPluginDirs(t *testing.T) {
cli := test.NewFakeCli(nil)
expected := []string{defaultUserPluginDir}
expected := []string{config.Path("cli-plugins")}
expected = append(expected, defaultSystemPluginDirs...)
assert.Equal(t, strings.Join(expected, ":"), strings.Join(getPluginDirs(cli), ":"))