add command gen service for cli

This commit is contained in:
John Guo
2022-04-22 18:17:10 +08:00
parent 023c4a19ae
commit 215a50675e
2 changed files with 11 additions and 3 deletions

View File

@ -109,7 +109,7 @@ func init() {
type cBuildInput struct {
g.Meta `name:"build" config:"gfcli.build"`
File string `name:"FILE" arg:"true" brief:"building file path"`
File string `name:"FILE" arg:"true" brief:"building file path"`
Name string `short:"n" name:"name" brief:"output binary name"`
Version string `short:"v" name:"version" brief:"output binary version"`
Arch string `short:"a" name:"arch" brief:"output binary architecture, multiple arch separated with ','"`

View File

@ -2,12 +2,13 @@ package utils
import (
"fmt"
"github.com/gogf/gf/v2/os/gproc"
)
var (
// gofmtPath is the binary path of command `gofmt`.
gofmtPath = gproc.SearchBinaryPath("gofmt")
gofmtPath = gproc.SearchBinaryPath("gofmt") // gofmtPath is the binary path of command `gofmt`.
goimportsPath = gproc.SearchBinaryPath("goimports") // gofmtPath is the binary path of command `goimports`.
)
// GoFmt formats the source file using command `gofmt -w -s PATH`.
@ -16,3 +17,10 @@ func GoFmt(path string) {
gproc.ShellExec(fmt.Sprintf(`%s -w -s %s`, gofmtPath, path))
}
}
// GoImports formats the source file using command `goimports -w PATH`.
func GoImports(path string) {
if goimportsPath != "" {
gproc.ShellExec(fmt.Sprintf(`%s -w %s`, goimportsPath, path))
}
}