|
|
@ -3,47 +3,39 @@ |
|
|
|
package main |
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"flag" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"strings" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
|
|
|
|
"v2ray.com/core/common" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
pkg = flag.String("pkg", "", "Target package") |
|
|
|
|
|
|
|
path = flag.String("path", "", "Path") |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func getCurrentPkg() (string, error) { |
|
|
|
flag.Parse() |
|
|
|
path, err := os.Getwd() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if len(*pkg) == 0 { |
|
|
|
return "", err |
|
|
|
panic("Package is not specified.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(*path) == 0 { |
|
|
|
|
|
|
|
panic("Path is not specified.") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return filepath.Base(path), nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
paths := strings.Split(*path, ",") |
|
|
|
func main() { |
|
|
|
for i := range paths { |
|
|
|
pkg, err := getCurrentPkg() |
|
|
|
paths[i] = "\"" + paths[i] + "\"" |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatal("Failed to get current package: ", err.Error()) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
pathStr := strings.Join(paths, ", ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) |
|
|
|
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("Failed to generate errors.generated.go: %v", err) |
|
|
|
log.Fatalf("Failed to generate errors.generated.go: %v", err) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
common.Must2(fmt.Fprintln(file, "package", *pkg)) |
|
|
|
fmt.Fprintln(file, "package", pkg) |
|
|
|
common.Must2(fmt.Fprintln(file, "")) |
|
|
|
fmt.Fprintln(file, "") |
|
|
|
common.Must2(fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\"")) |
|
|
|
fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\"") |
|
|
|
common.Must2(fmt.Fprintln(file, "")) |
|
|
|
fmt.Fprintln(file, "") |
|
|
|
common.Must2(fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("+pathStr+") }")) |
|
|
|
fmt.Fprintln(file, "type errPathObjHolder struct {}") |
|
|
|
|
|
|
|
fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }") |
|
|
|
|
|
|
|
|
|
|
|
common.Must(file.Close()) |
|
|
|
file.Close() |
|
|
|
} |
|
|
|
} |
|
|
|