mirror of
https://github.com/cubixle/tuugen.git
synced 2026-04-24 21:14:41 +01:00
40 lines
858 B
Go
40 lines
858 B
Go
package tuugen
|
|
|
|
import "os/exec"
|
|
|
|
func runCommand(cmd string, args []string) error {
|
|
c := exec.Command(cmd, args...)
|
|
err := c.Start()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
err = c.Wait()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func GenerateProtos() error {
|
|
cmd := "protoc"
|
|
args := []string{"-I", ".:${GOPATH}/src", "--go_out=.", "--go-grpc_out=.", "service.proto"}
|
|
return runCommand(cmd, args)
|
|
}
|
|
|
|
func GoFmt() error {
|
|
cmd := "gofmt"
|
|
return runCommand(cmd, []string{})
|
|
}
|
|
|
|
func GoImports() error {
|
|
if err := runCommand("goimports", []string{"-w", "internal/service/service.go"}); err != nil {
|
|
return err
|
|
}
|
|
return runCommand("goimports", []string{"-w", "internal/interactors/interactors.go"})
|
|
}
|
|
|
|
func GoModInit(importPath string) error {
|
|
runCommand("go", []string{"mod", "init", importPath})
|
|
return runCommand("go", []string{"mod", "tidy"})
|
|
}
|