From 215a50675e4087357e28c0a7c26068537b5bdd72 Mon Sep 17 00:00:00 2001 From: John Guo Date: Fri, 22 Apr 2022 18:17:10 +0800 Subject: [PATCH] add command gen service for cli --- cmd/gf/internal/cmd/cmd_build.go | 2 +- cmd/gf/internal/utility/utils/utils.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/gf/internal/cmd/cmd_build.go b/cmd/gf/internal/cmd/cmd_build.go index 2792e06f7..df85957eb 100644 --- a/cmd/gf/internal/cmd/cmd_build.go +++ b/cmd/gf/internal/cmd/cmd_build.go @@ -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 ','"` diff --git a/cmd/gf/internal/utility/utils/utils.go b/cmd/gf/internal/utility/utils/utils.go index 15a689bd8..87ea5f4c5 100644 --- a/cmd/gf/internal/utility/utils/utils.go +++ b/cmd/gf/internal/utility/utils/utils.go @@ -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)) + } +}