From ee3dc589c673d8f905b5f4fded89bee17368b9f8 Mon Sep 17 00:00:00 2001 From: Nikola Kovacs Date: Fri, 23 Jun 2017 22:26:10 +0200 Subject: [PATCH] Search vendor directories when using import path Fixes #75 --- locator/locator.go | 4 ++-- main.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/locator/locator.go b/locator/locator.go index 6fa701d..15ae339 100644 --- a/locator/locator.go +++ b/locator/locator.go @@ -26,7 +26,7 @@ func GetInterfaceFromFilePath(interfaceName, filePath string) (*model.InterfaceT return nil, err } - vendorPaths, err := vendorPathsForDirPath(dirPath) + vendorPaths, err := VendorPathsForDirPath(dirPath) if err != nil { return nil, err } @@ -145,7 +145,7 @@ func importPathForDirPath(sourcePath string) (string, error) { return "", fmt.Errorf("Path '%s' is not on GOPATH", sourcePath) } -func vendorPathsForDirPath(dirPath string) ([]string, error) { +func VendorPathsForDirPath(dirPath string) ([]string, error) { dirPath, err := filepath.Abs(dirPath) if err != nil { return nil, err diff --git a/main.go b/main.go index 0b616b3..1341201 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,11 @@ func generateFake(interfaceName, sourcePackageDir, importPath, outputPath, desti var err error var iface *model.InterfaceToFake if sourcePackageDir == "" { - iface, err = locator.GetInterfaceFromImportPath(interfaceName, importPath) + var vendorPaths []string + vendorPaths, err = locator.VendorPathsForDirPath(".") + if err == nil { + iface, err = locator.GetInterfaceFromImportPath(interfaceName, importPath, vendorPaths...) + } } else { iface, err = locator.GetInterfaceFromFilePath(interfaceName, sourcePackageDir) }