mirror of
https://github.com/spf13/cobra
synced 2024-12-26 22:37:08 +00:00
parent
1d9d665f6f
commit
2a6ed7a106
2 changed files with 9 additions and 10 deletions
|
@ -15,7 +15,6 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
@ -117,9 +116,9 @@ func init() {
|
|||
data["parentName"] = parentName()
|
||||
data["cmdName"] = cmdName
|
||||
|
||||
err := writeTemplateToFile(ProjectPath()+string(os.PathSeparator)+guessCmdDir(), cmdName+".go", template, data)
|
||||
err := writeTemplateToFile(filepath.Join(ProjectPath(), guessCmdDir()), cmdName+".go", template, data)
|
||||
if err != nil {
|
||||
er(err)
|
||||
}
|
||||
fmt.Println(cmdName, "created at", filepath.Join(ProjectPath()+string(os.PathSeparator)+guessCmdDir(), cmdName+".go"))
|
||||
fmt.Println(cmdName, "created at", filepath.Join(ProjectPath(), guessCmdDir(), cmdName+".go"))
|
||||
}
|
||||
|
|
|
@ -104,11 +104,11 @@ func guessImportPath() string {
|
|||
er("Cobra only supports project within $GOPATH")
|
||||
}
|
||||
|
||||
return strings.TrimPrefix(projectPath, getSrcPath())
|
||||
return filepath.Clean(strings.TrimPrefix(projectPath, getSrcPath()))
|
||||
}
|
||||
|
||||
func getSrcPath() string {
|
||||
return os.Getenv("GOPATH") + string(os.PathSeparator) + "src" + string(os.PathSeparator)
|
||||
return filepath.Join(os.Getenv("GOPATH"), "src") + string(os.PathSeparator)
|
||||
}
|
||||
|
||||
func projectName() string {
|
||||
|
@ -129,7 +129,7 @@ func guessProjectPath() {
|
|||
// if we are in the cmd directory.. back up
|
||||
for _, c := range cmdDirs {
|
||||
if base == c {
|
||||
projectPath = filepath.Clean(filepath.Dir(x))
|
||||
projectPath = filepath.Dir(x)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -154,10 +154,10 @@ func guessProjectPath() {
|
|||
switch count {
|
||||
// If only one directory deep assume "github.com"
|
||||
case 1:
|
||||
projectPath = filepath.Clean(srcPath + "github.com" + string(os.PathSeparator) + inputPath)
|
||||
projectPath = filepath.Join(srcPath, "github.com", inputPath)
|
||||
return
|
||||
case 2:
|
||||
projectPath = filepath.Clean(srcPath + inputPath)
|
||||
projectPath = filepath.Join(srcPath, inputPath)
|
||||
return
|
||||
default:
|
||||
er("Unknown directory")
|
||||
|
@ -167,12 +167,12 @@ func guessProjectPath() {
|
|||
if projectBase == "" {
|
||||
x, err := getWd()
|
||||
if err == nil {
|
||||
projectPath = filepath.Clean(x + string(os.PathSeparator) + inputPath)
|
||||
projectPath = filepath.Join(x, inputPath)
|
||||
return
|
||||
}
|
||||
er(err)
|
||||
} else {
|
||||
projectPath = filepath.Clean(srcPath + projectBase + string(os.PathSeparator) + inputPath)
|
||||
projectPath = filepath.Join(srcPath, projectBase, inputPath)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue