Fix go generate core/format.go (#725)

This commit is contained in:
yuhan6665 2021-09-27 01:45:02 -04:00 committed by GitHub
parent ed39fc3b79
commit 1ef824c0b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View file

@ -1,4 +1,4 @@
package core package core
//go:generate go install -v golang.org/x/tools/cmd/goimports@latest //go:generate go install -v golang.org/x/tools/cmd/goimports@latest
//go:generate go run ../infra/vformat/ //go:generate go run ../infra/vformat/main.go -pwd ./..

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"go/build" "go/build"
"io/ioutil" "io/ioutil"
@ -11,6 +12,8 @@ import (
"strings" "strings"
) )
var directory = flag.String("pwd", "", "Working directory of Xray vformat.")
// envFile returns the name of the Go environment configuration file. // envFile returns the name of the Go environment configuration file.
// Copy from https://github.com/golang/go/blob/c4f2a9788a7be04daf931ac54382fbe2cb754938/src/cmd/go/internal/cfg/cfg.go#L150-L166 // Copy from https://github.com/golang/go/blob/c4f2a9788a7be04daf931ac54382fbe2cb754938/src/cmd/go/internal/cfg/cfg.go#L150-L166
func envFile() (string, error) { func envFile() (string, error) {
@ -106,12 +109,22 @@ func RunMany(binary string, args, files []string) {
} }
func main() { func main() {
pwd, err := os.Getwd() flag.Usage = func() {
if err != nil { fmt.Fprintf(flag.CommandLine.Output(), "Usage of vformat:\n")
fmt.Println("Can not get current working directory.") flag.PrintDefaults()
os.Exit(1) }
flag.Parse()
if !filepath.IsAbs(*directory) {
pwd, wdErr := os.Getwd()
if wdErr != nil {
fmt.Println("Can not get current working directory.")
os.Exit(1)
}
*directory = filepath.Join(pwd, *directory)
} }
pwd := *directory
GOBIN := GetGOBIN() GOBIN := GetGOBIN()
binPath := os.Getenv("PATH") binPath := os.Getenv("PATH")
pathSlice := []string{pwd, GOBIN, binPath} pathSlice := []string{pwd, GOBIN, binPath}
@ -140,7 +153,7 @@ func main() {
} }
rawFilesSlice := make([]string, 0) rawFilesSlice := make([]string, 0)
walkErr := filepath.Walk("./", func(path string, info os.FileInfo, err error) error { walkErr := filepath.Walk(pwd, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return err return err