add os.PathSeparator to the return value of findCmdDir func

add func findCmdSuffix

fix comment

change findCmdSuffix to findCmdPath

fix
This commit is contained in:
bonfy 2018-04-12 16:05:36 +08:00
parent cd30c2a7e9
commit 70ca0b2f14

View file

@ -92,7 +92,8 @@ func NewProjectFromPath(absPath string) *Project {
} }
p := new(Project) p := new(Project)
p.absPath = strings.TrimSuffix(absPath, findCmdDir(absPath))
p.absPath = findCmdPath(absPath)
p.name = filepath.ToSlash(trimSrcPath(p.absPath, p.SrcPath())) p.name = filepath.ToSlash(trimSrcPath(p.absPath, p.SrcPath()))
return p return p
} }
@ -130,6 +131,15 @@ func (p *Project) CmdPath() string {
return p.cmdPath return p.cmdPath
} }
// findCmdPath returns the cmd path.
func findCmdPath(path string) string {
cmdDir := findCmdDir(path)
if filepathHasPrefix(cmdDir, string(os.PathSeparator)) {
return strings.TrimSuffix(path, cmdDir)
}
return strings.TrimSuffix(path, string(os.PathSeparator)+cmdDir)
}
// findCmdDir checks if base of absPath is cmd dir and returns it or // findCmdDir checks if base of absPath is cmd dir and returns it or
// looks for existing cmd dir in absPath. // looks for existing cmd dir in absPath.
func findCmdDir(absPath string) string { func findCmdDir(absPath string) string {