ListPlugins returns list of plugin paths.
()
| 163 | |
| 164 | // ListPlugins returns list of plugin paths. |
| 165 | func (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 |
| 201 | type PathVerifier interface { |