From 55a1f6eb73f958d3f915f8eafd0d056e428919d3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 19 Jun 2024 14:02:40 +0200 Subject: [PATCH] cli-plugins/manager: add GoDoc for getPluginDirs, defaultSystemPluginDirs Add some documentation about their purpose, and document order of preference when resolving plugins. Signed-off-by: Sebastiaan van Stijn --- cli-plugins/manager/manager.go | 10 ++++++++++ cli-plugins/manager/manager_unix.go | 16 ++++++++++++++-- cli-plugins/manager/manager_windows.go | 10 ++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cli-plugins/manager/manager.go b/cli-plugins/manager/manager.go index 031b04f6bb..9886830240 100644 --- a/cli-plugins/manager/manager.go +++ b/cli-plugins/manager/manager.go @@ -49,6 +49,16 @@ func IsNotFound(err error) bool { return ok } +// getPluginDirs returns the platform-specific locations to search for plugins +// in order of preference. +// +// Plugin-discovery is performed in the following order of preference: +// +// 1. The "cli-plugins" directory inside the CLIs [config.Path] (usually "~/.docker/cli-plugins"). +// 2. Additional plugin directories as configured through [ConfigFile.CLIPluginsExtraDirs]. +// 3. Platform-specific defaultSystemPluginDirs. +// +// [ConfigFile.CLIPluginsExtraDirs]: https://pkg.go.dev/github.com/docker/cli@v26.1.4+incompatible/cli/config/configfile#ConfigFile.CLIPluginsExtraDirs func getPluginDirs(cfg *configfile.ConfigFile) ([]string, error) { var pluginDirs []string diff --git a/cli-plugins/manager/manager_unix.go b/cli-plugins/manager/manager_unix.go index 000c058df0..f546dc3849 100644 --- a/cli-plugins/manager/manager_unix.go +++ b/cli-plugins/manager/manager_unix.go @@ -2,7 +2,19 @@ package manager +// defaultSystemPluginDirs are the platform-specific locations to search +// for plugins in order of preference. +// +// Plugin-discovery is performed in the following order of preference: +// +// 1. The "cli-plugins" directory inside the CLIs config-directory (usually "~/.docker/cli-plugins"). +// 2. Additional plugin directories as configured through [ConfigFile.CLIPluginsExtraDirs]. +// 3. Platform-specific defaultSystemPluginDirs (as defined below). +// +// [ConfigFile.CLIPluginsExtraDirs]: https://pkg.go.dev/github.com/docker/cli@v26.1.4+incompatible/cli/config/configfile#ConfigFile.CLIPluginsExtraDirs var defaultSystemPluginDirs = []string{ - "/usr/local/lib/docker/cli-plugins", "/usr/local/libexec/docker/cli-plugins", - "/usr/lib/docker/cli-plugins", "/usr/libexec/docker/cli-plugins", + "/usr/local/lib/docker/cli-plugins", + "/usr/local/libexec/docker/cli-plugins", + "/usr/lib/docker/cli-plugins", + "/usr/libexec/docker/cli-plugins", } diff --git a/cli-plugins/manager/manager_windows.go b/cli-plugins/manager/manager_windows.go index 2ce5a75973..e8b5598e59 100644 --- a/cli-plugins/manager/manager_windows.go +++ b/cli-plugins/manager/manager_windows.go @@ -5,6 +5,16 @@ import ( "path/filepath" ) +// defaultSystemPluginDirs are the platform-specific locations to search +// for plugins in order of preference. +// +// Plugin-discovery is performed in the following order of preference: +// +// 1. The "cli-plugins" directory inside the CLIs config-directory (usually "~/.docker/cli-plugins"). +// 2. Additional plugin directories as configured through [ConfigFile.CLIPluginsExtraDirs]. +// 3. Platform-specific defaultSystemPluginDirs (as defined below). +// +// [ConfigFile.CLIPluginsExtraDirs]: https://pkg.go.dev/github.com/docker/cli@v26.1.4+incompatible/cli/config/configfile#ConfigFile.CLIPluginsExtraDirs var defaultSystemPluginDirs = []string{ filepath.Join(os.Getenv("ProgramData"), "Docker", "cli-plugins"), filepath.Join(os.Getenv("ProgramFiles"), "Docker", "cli-plugins"),