goctl added
This commit is contained in:
52
tools/goctl/gen/makefile.go
Normal file
52
tools/goctl/gen/makefile.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
func GenerateMakefile(goFile, namespace string) error {
|
||||
relPath, err := util.PathFromGoSrc()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
movePath, err := getMovePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out, err := util.CreateIfNotExist("Makefile")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
t := template.Must(template.New("makefile").Parse(makefileTemplate))
|
||||
return t.Execute(out, map[string]string{
|
||||
"rootRelPath": movePath,
|
||||
"relPath": relPath,
|
||||
"exeFile": util.FileNameWithoutExt(goFile),
|
||||
"namespace": namespace,
|
||||
})
|
||||
}
|
||||
|
||||
func getMovePath() (string, error) {
|
||||
relPath, err := util.PathFromGoSrc()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var builder strings.Builder
|
||||
for range strings.Split(relPath, "/") {
|
||||
builder.WriteString("../")
|
||||
}
|
||||
|
||||
if move := builder.String(); len(move) == 0 {
|
||||
return ".", nil
|
||||
} else {
|
||||
return move, nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user