Skip to content

Commit

Permalink
Fix go generate core/format.go (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhan6665 committed Sep 27, 2021
1 parent ed39fc3 commit 1ef824c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/format.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core

//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 ./..
23 changes: 18 additions & 5 deletions infra/vformat/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"go/build"
"io/ioutil"
Expand All @@ -11,6 +12,8 @@ import (
"strings"
)

var directory = flag.String("pwd", "", "Working directory of Xray vformat.")

// 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
func envFile() (string, error) {
Expand Down Expand Up @@ -106,12 +109,22 @@ func RunMany(binary string, args, files []string) {
}

func main() {
pwd, err := os.Getwd()
if err != nil {
fmt.Println("Can not get current working directory.")
os.Exit(1)
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of vformat:\n")
flag.PrintDefaults()
}
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()
binPath := os.Getenv("PATH")
pathSlice := []string{pwd, GOBIN, binPath}
Expand Down Expand Up @@ -140,7 +153,7 @@ func main() {
}

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 {
fmt.Println(err)
return err
Expand Down

0 comments on commit 1ef824c

Please sign in to comment.