Skip to content

Commit

Permalink
Ensure plugins default search path obeys --config
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ian Campbell committed Jan 29, 2019
1 parent 197811b commit c8f1f1e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions cli-plugins/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cli-plugins/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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), ":"))
Expand Down

0 comments on commit c8f1f1e

Please sign in to comment.