mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"runtime"
|
|
"syscall"
|
|
|
|
"github.com/Dreamacro/clash/config"
|
|
C "github.com/Dreamacro/clash/constant"
|
|
"github.com/Dreamacro/clash/hub"
|
|
"github.com/Dreamacro/clash/log"
|
|
)
|
|
|
|
var (
|
|
version bool
|
|
homeDir string
|
|
configFile string
|
|
)
|
|
|
|
func init() {
|
|
flag.StringVar(&homeDir, "d", "", "set configuration directory")
|
|
flag.StringVar(&configFile, "f", "", "specify configuration file")
|
|
flag.BoolVar(&version, "v", false, "show current version of clash")
|
|
flag.Parse()
|
|
}
|
|
|
|
func main() {
|
|
if version {
|
|
fmt.Printf("Clash %s %s %s %s\n", C.Version, runtime.GOOS, runtime.GOARCH, C.BuildTime)
|
|
return
|
|
}
|
|
|
|
if homeDir != "" {
|
|
if !filepath.IsAbs(homeDir) {
|
|
currentDir, _ := os.Getwd()
|
|
homeDir = filepath.Join(currentDir, homeDir)
|
|
}
|
|
C.SetHomeDir(homeDir)
|
|
}
|
|
|
|
if configFile != "" {
|
|
if !filepath.IsAbs(configFile) {
|
|
currentDir, _ := os.Getwd()
|
|
configFile = filepath.Join(currentDir, configFile)
|
|
}
|
|
C.SetConfig(configFile)
|
|
} else {
|
|
configFile := filepath.Join(C.Path.HomeDir(), C.Path.Config())
|
|
C.SetConfig(configFile)
|
|
}
|
|
|
|
if err := config.Init(C.Path.HomeDir()); err != nil {
|
|
log.Fatalln("Initial configuration directory error: %s", err.Error())
|
|
}
|
|
|
|
if err := hub.Parse(); err != nil {
|
|
log.Fatalln("Parse config error: %s", err.Error())
|
|
}
|
|
|
|
sigCh := make(chan os.Signal, 1)
|
|
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
|
<-sigCh
|
|
}
|