You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
kratos/tool/kratos/build.go

47 lines
857 B

package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"github.com/urfave/cli"
)
func buildAction(c *cli.Context) error {
base, err := os.Getwd()
if err != nil {
panic(err)
}
args := append([]string{"build"}, c.Args()...)
cmd := exec.Command("go", args...)
cmd.Dir = buildDir(base, "cmd", 5)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
fmt.Printf("directory: %s\n", cmd.Dir)
fmt.Printf("kratos: %s\n", Version)
if err := cmd.Run(); err != nil {
panic(err)
}
fmt.Println("build success.")
return nil
}
func buildDir(base string, cmd string, n int) string {
dirs, err := ioutil.ReadDir(base)
if err != nil {
panic(err)
}
for _, d := range dirs {
if d.IsDir() && d.Name() == cmd {
return path.Join(base, cmd)
}
}
if n <= 1 {
return base
}
return buildDir(filepath.Dir(base), cmd, n-1)
}