improving project path guessing

This commit is contained in:
spf13 2015-11-06 10:44:59 -05:00
parent bc980b80a1
commit 1d9d665f6f
2 changed files with 8 additions and 7 deletions

View File

@ -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
}
}

View File

@ -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")
}