diff --git a/cobra/cmd/helpers.go b/cobra/cmd/helpers.go index d5c276f..8730062 100644 --- a/cobra/cmd/helpers.go +++ b/cobra/cmd/helpers.go @@ -143,7 +143,7 @@ func guessProjectPath() { srcPath := getSrcPath() // if provided, inspect for logical locations if strings.ContainsRune(inputPath, os.PathSeparator) { - if filepath.IsAbs(inputPath) { + if filepath.IsAbs(inputPath) || filepath.HasPrefix(inputPath, string(os.PathSeparator)) { // if Absolute, use it projectPath = filepath.Clean(inputPath) return diff --git a/cobra/cmd/helpers_test.go b/cobra/cmd/helpers_test.go index dc9b3f3..bd0f759 100644 --- a/cobra/cmd/helpers_test.go +++ b/cobra/cmd/helpers_test.go @@ -31,7 +31,7 @@ func reset() { func TestProjectPath(t *testing.T) { checkGuess(t, "", filepath.Join("github.com", "spf13", "hugo"), filepath.Join(getSrcPath(), "github.com", "spf13", "hugo")) checkGuess(t, "", filepath.Join("spf13", "hugo"), filepath.Join(getSrcPath(), "github.com", "spf13", "hugo")) - checkGuess(t, "", filepath.Join("/", "bar", "foo"), filepath.Join(getSrcPath(), "bar", "foo")) + checkGuess(t, "", filepath.Join("/", "bar", "foo"), filepath.Join("/", "bar", "foo")) checkGuess(t, "/bar/foo", "baz", filepath.Join("/", "bar", "foo", "baz")) checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo")) checkGuess(t, "/bar/foo/command", "", filepath.Join("/", "bar", "foo"))