main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "os"
  7. "strings"
  8. "v2ray.com/core/common"
  9. )
  10. var (
  11. pkg = flag.String("pkg", "", "Target package")
  12. path = flag.String("path", "", "Path")
  13. )
  14. func main() {
  15. flag.Parse()
  16. if len(*pkg) == 0 {
  17. panic("Package is not specified.")
  18. }
  19. if len(*path) == 0 {
  20. panic("Path is not specified.")
  21. }
  22. paths := strings.Split(*path, ",")
  23. for i := range paths {
  24. paths[i] = "\"" + paths[i] + "\""
  25. }
  26. pathStr := strings.Join(paths, ", ")
  27. file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
  28. if err != nil {
  29. log.Fatalf("Failed to generate errors.generated.go: %v", err)
  30. }
  31. common.Must2(fmt.Fprintln(file, "package", *pkg))
  32. common.Must2(fmt.Fprintln(file, ""))
  33. common.Must2(fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\""))
  34. common.Must2(fmt.Fprintln(file, ""))
  35. common.Must2(fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("+pathStr+") }"))
  36. common.Must(file.Close())
  37. }