mirror of
https://github.com/spf13/cobra
synced 2025-05-06 05:17:21 +00:00
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:
parent
cd30c2a7e9
commit
70ca0b2f14
1 changed files with 11 additions and 1 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue