Feature: add configuration test command (#524)

This commit is contained in:
Wu Haotian 2020-02-29 17:48:26 +08:00 committed by GitHub
parent c4994d6429
commit e81b88fb94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

14
main.go
View file

@ -10,13 +10,16 @@ import (
"syscall"
"github.com/Dreamacro/clash/config"
"github.com/Dreamacro/clash/constant"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/hub"
"github.com/Dreamacro/clash/hub/executor"
"github.com/Dreamacro/clash/log"
)
var (
version bool
testConfig bool
homeDir string
configFile string
)
@ -25,6 +28,7 @@ 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.BoolVar(&testConfig, "t", false, "test configuration and exit")
flag.Parse()
}
@ -57,6 +61,16 @@ func main() {
log.Fatalln("Initial configuration directory error: %s", err.Error())
}
if testConfig {
if _, err := executor.Parse(); err != nil {
log.Errorln(err.Error())
fmt.Printf("configuration file %s test failed\n", constant.Path.Config())
os.Exit(1)
}
fmt.Printf("configuration file %s test is successful\n", constant.Path.Config())
return
}
if err := hub.Parse(); err != nil {
log.Fatalln("Parse config error: %s", err.Error())
}