fix issue of space char in binary pth of gofmt/goimports
@@ -15,6 +15,16 @@ var (
goimportsPath = gproc.SearchBinaryPath("goimports") // gofmtPath is the binary path of command `goimports`.
)
+func init() {
+ // Wraps the command binary path with char '"' if there's space char in the path.
+ if gstr.Contains(gofmtPath, " ") {
+ gofmtPath = fmt.Sprintf(`"%s"`, gofmtPath)
+ }
+ if gstr.Contains(goimportsPath, " ") {
+ goimportsPath = fmt.Sprintf(`"%s"`, goimportsPath)
+ }
+}
+
// GoFmt formats the source file using command `gofmt -w -s PATH`.
func GoFmt(path string) {
if gofmtPath == "" {
