MCPcopy
hub / github.com/kubernetes/kubectl / ListPlugins

Method ListPlugins

pkg/cmd/plugin/plugin.go:165–198  ·  view source on GitHub ↗

ListPlugins returns list of plugin paths.

()

Source from the content-addressed store, hash-verified

163
164// ListPlugins returns list of plugin paths.
165func (o *PluginListOptions) ListPlugins() ([]string, []error) {
166 plugins := []string{}
167 errors := []error{}
168
169 for _, dir := range uniquePathsList(o.PluginPaths) {
170 if len(strings.TrimSpace(dir)) == 0 {
171 continue
172 }
173
174 files, err := os.ReadDir(dir)
175 if err != nil {
176 if _, ok := err.(*os.PathError); ok {
177 fmt.Fprintf(o.ErrOut, "Unable to read directory %q from your PATH: %v. Skipping...\n", dir, err)
178 continue
179 }
180
181 errors = append(errors, fmt.Errorf("error: unable to read directory %q in your PATH: %v", dir, err))
182 continue
183 }
184
185 for _, f := range files {
186 if f.IsDir() {
187 continue
188 }
189 if !hasValidPrefix(f.Name(), ValidPluginFilenamePrefixes) {
190 continue
191 }
192
193 plugins = append(plugins, filepath.Join(dir, f.Name()))
194 }
195 }
196
197 return plugins, errors
198}
199
200// pathVerifier receives a path and determines if it is valid or not
201type PathVerifier interface {

Callers 3

TestListPluginsFunction · 0.95
registerPluginCommandsFunction · 0.95
RunMethod · 0.95

Calls 4

uniquePathsListFunction · 0.85
hasValidPrefixFunction · 0.85
NameMethod · 0.65
JoinMethod · 0.45

Tested by 1

TestListPluginsFunction · 0.76