From b68af433894e0abdf9965b47ba2310b76cc5ed73 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Tue, 16 Oct 2018 13:12:36 +0800 Subject: [PATCH] Improve: support custom configuration directory --- main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.go b/main.go index 57e834c2..7273c4d5 100644 --- a/main.go +++ b/main.go @@ -4,20 +4,40 @@ import ( "os" "os/signal" "syscall" + "flag" + "path" "github.com/Dreamacro/clash/config" "github.com/Dreamacro/clash/hub" "github.com/Dreamacro/clash/proxy" "github.com/Dreamacro/clash/tunnel" + C "github.com/Dreamacro/clash/constant" log "github.com/sirupsen/logrus" ) +var ( + homedir string +) + +func init() { + flag.StringVar(&homedir, "d", "", "set configuration directory") + flag.Parse() +} + func main() { tunnel.Instance().Run() proxy.Instance().Run() hub.Run() + if (homedir != "") { + if !path.IsAbs(homedir) { + currentDir, _ := os.Getwd() + homedir = path.Join(currentDir, homedir) + } + C.SetHomeDir(homedir) + } + config.Init() err := config.Instance().Parse() if err != nil {