diff --git a/cobra/cmd/project.go b/cobra/cmd/project.go index 7ddb8258..6cf0449e 100644 --- a/cobra/cmd/project.go +++ b/cobra/cmd/project.go @@ -92,7 +92,8 @@ func NewProjectFromPath(absPath string) *Project { } p := new(Project) - p.absPath = strings.TrimSuffix(absPath, findCmdDir(absPath)) + + p.absPath = findCmdPath(absPath) p.name = filepath.ToSlash(trimSrcPath(p.absPath, p.SrcPath())) return p } @@ -130,6 +131,15 @@ func (p *Project) CmdPath() string { 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 // looks for existing cmd dir in absPath. func findCmdDir(absPath string) string {