discover.go 639 B

12345678910111213141516171819202122232425262728
  1. package plugin
  2. import (
  3. "path/filepath"
  4. )
  5. // Discover discovers plugins that are in a given directory.
  6. //
  7. // The directory doesn't need to be absolute. For example, "." will work fine.
  8. //
  9. // This currently assumes any file matching the glob is a plugin.
  10. // In the future this may be smarter about checking that a file is
  11. // executable and so on.
  12. //
  13. // TODO: test
  14. func Discover(glob, dir string) ([]string, error) {
  15. var err error
  16. // Make the directory absolute if it isn't already
  17. if !filepath.IsAbs(dir) {
  18. dir, err = filepath.Abs(dir)
  19. if err != nil {
  20. return nil, err
  21. }
  22. }
  23. return filepath.Glob(filepath.Join(dir, glob))
  24. }