Feat: add --datapath flag for custom data folder

This commit is contained in:
loyalsoldier 2020-04-29 11:58:00 +08:00
parent 440aef863b
commit 1271c8c4e2

15
main.go
View File

@ -3,6 +3,7 @@ package main
import (
"bufio"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
@ -14,6 +15,8 @@ import (
"v2ray.com/core/app/router"
)
var dataPath = flag.String("datapath", "", "Path to the data folder")
type Entry struct {
Type string
Value string
@ -216,7 +219,15 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) {
}
func main() {
dir, err := DetectPath(os.Getenv("GOPATH"))
flag.Parse()
var dir string
var err error
if *dataPath != "" {
dir = *dataPath
} else {
dir, err = DetectPath(os.Getenv("GOPATH"))
}
if err != nil {
fmt.Println("Failed: ", err)
return
@ -263,5 +274,7 @@ func main() {
}
if err := ioutil.WriteFile("dlc.dat", protoBytes, 0777); err != nil {
fmt.Println("Failed: ", err)
} else {
fmt.Println("dlc.dat has been generated successfully.")
}
}