Skip to content

Commit

Permalink
configurable detectors list
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Oct 13, 2015
1 parent ed211a0 commit 86e3d1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ func init() {
// Detect turns a source string into another source string if it is
// detected to be of a known pattern.
//
// The third parameter should be the list of detectors to use in the
// order to try them. If you don't want to configure this, just use
// the global Detectors variable.
//
// This is safe to be called with an already valid source string: Detect
// will just return it.
func Detect(src string, pwd string) (string, error) {
func Detect(src string, pwd string, ds []Detector) (string, error) {
getForce, getSrc := getForcedGetter(src)

// Separate out the subdir if there is one, we don't pass that to detect
Expand All @@ -45,7 +49,7 @@ func Detect(src string, pwd string) (string, error) {
return src, nil
}

for _, d := range Detectors {
for _, d := range ds {
result, ok, err := d.Detect(getSrc, pwd)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestDetect(t *testing.T) {
}

for i, tc := range cases {
output, err := Detect(tc.Input, tc.Pwd)
output, err := Detect(tc.Input, tc.Pwd, Detectors)
if err != nil != tc.Err {
t.Fatalf("%d: bad err: %s", i, err)
}
Expand Down

0 comments on commit 86e3d1a

Please sign in to comment.