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