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