Feature: add configuration test command (#524)
This commit is contained in:
parent
717482065c
commit
1ff02eb411
1 changed files with 14 additions and 0 deletions
14
main.go
14
main.go
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue