mirror of
https://github.com/spf13/cobra
synced 2025-05-06 13:27:26 +00:00
change findCmdSuffix to findCmdPath
This commit is contained in:
parent
219242841f
commit
ccc29509df
1 changed files with 5 additions and 5 deletions
|
@ -93,8 +93,7 @@ func NewProjectFromPath(absPath string) *Project {
|
||||||
|
|
||||||
p := new(Project)
|
p := new(Project)
|
||||||
|
|
||||||
cmdDir := findCmdDir(absPath)
|
p.absPath = findCmdSuffix(absPath)
|
||||||
p.absPath = strings.TrimSuffix(absPath, findCmdSuffix(cmdDir))
|
|
||||||
p.name = filepath.ToSlash(trimSrcPath(p.absPath, p.SrcPath()))
|
p.name = filepath.ToSlash(trimSrcPath(p.absPath, p.SrcPath()))
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
@ -133,11 +132,12 @@ func (p *Project) CmdPath() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// findCmdSuffix returns the cmd dir start with file path separator.
|
// findCmdSuffix returns the cmd dir start with file path separator.
|
||||||
func findCmdSuffix(cmdDir string) string {
|
func findCmdSuffix(path string) string {
|
||||||
|
cmdDir := findCmdDir(path)
|
||||||
if filepathHasPrefix(cmdDir, string(os.PathSeparator)) {
|
if filepathHasPrefix(cmdDir, string(os.PathSeparator)) {
|
||||||
return cmdDir
|
return strings.TrimSuffix(path, cmdDir)
|
||||||
}
|
}
|
||||||
return string(os.PathSeparator) + cmdDir
|
return 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
|
||||||
|
|
Loading…
Add table
Reference in a new issue