diff --git a/cobra/cmd/helpers.go b/cobra/cmd/helpers.go index 28f70039..b90e3e7e 100644 --- a/cobra/cmd/helpers.go +++ b/cobra/cmd/helpers.go @@ -129,13 +129,13 @@ func guessProjectPath() { // if we are in the cmd directory.. back up for _, c := range cmdDirs { if base == c { - projectPath = filepath.Dir(x) + projectPath = filepath.Clean(filepath.Dir(x)) return } } if projectPath == "" { - projectPath = x + projectPath = filepath.Clean(x) return } } @@ -145,7 +145,7 @@ func guessProjectPath() { if strings.ContainsRune(inputPath, os.PathSeparator) { if filepath.IsAbs(inputPath) { // if Absolute, use it - projectPath = inputPath + projectPath = filepath.Clean(inputPath) return } // If not absolute but contains slashes.. assuming it means create it from $GOPATH @@ -154,10 +154,10 @@ func guessProjectPath() { switch count { // If only one directory deep assume "github.com" case 1: - projectPath = srcPath + "github.com" + string(os.PathSeparator) + inputPath + projectPath = filepath.Clean(srcPath + "github.com" + string(os.PathSeparator) + inputPath) return case 2: - projectPath = srcPath + inputPath + projectPath = filepath.Clean(srcPath + inputPath) return default: er("Unknown directory") @@ -167,12 +167,12 @@ func guessProjectPath() { if projectBase == "" { x, err := getWd() if err == nil { - projectPath = x + string(os.PathSeparator) + inputPath + projectPath = filepath.Clean(x + string(os.PathSeparator) + inputPath) return } er(err) } else { - projectPath = srcPath + projectBase + string(os.PathSeparator) + inputPath + projectPath = filepath.Clean(srcPath + projectBase + string(os.PathSeparator) + inputPath) return } } diff --git a/cobra/cmd/helpers_test.go b/cobra/cmd/helpers_test.go index 26737c93..564ddbe5 100644 --- a/cobra/cmd/helpers_test.go +++ b/cobra/cmd/helpers_test.go @@ -35,4 +35,5 @@ func TestProjectPath(t *testing.T) { checkGuess(t, "/bar/foo/cmd", "", "/bar/foo") checkGuess(t, "/bar/foo/command", "", "/bar/foo") checkGuess(t, "/bar/foo/commands", "", "/bar/foo") + checkGuess(t, "github.com/spf13/hugo/../hugo", "", "github.com/spf13/hugo") }