Feature: add configuration test command (#524)
This commit is contained in:
parent
c4994d6429
commit
e81b88fb94
1 changed files with 14 additions and 0 deletions
14
main.go
14
main.go
|
@ -10,13 +10,16 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/config"
|
"github.com/Dreamacro/clash/config"
|
||||||
|
"github.com/Dreamacro/clash/constant"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/hub"
|
"github.com/Dreamacro/clash/hub"
|
||||||
|
"github.com/Dreamacro/clash/hub/executor"
|
||||||
"github.com/Dreamacro/clash/log"
|
"github.com/Dreamacro/clash/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version bool
|
version bool
|
||||||
|
testConfig bool
|
||||||
homeDir string
|
homeDir string
|
||||||
configFile string
|
configFile string
|
||||||
)
|
)
|
||||||
|
@ -25,6 +28,7 @@ func init() {
|
||||||
flag.StringVar(&homeDir, "d", "", "set configuration directory")
|
flag.StringVar(&homeDir, "d", "", "set configuration directory")
|
||||||
flag.StringVar(&configFile, "f", "", "specify configuration file")
|
flag.StringVar(&configFile, "f", "", "specify configuration file")
|
||||||
flag.BoolVar(&version, "v", false, "show current version of clash")
|
flag.BoolVar(&version, "v", false, "show current version of clash")
|
||||||
|
flag.BoolVar(&testConfig, "t", false, "test configuration and exit")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +61,16 @@ func main() {
|
||||||
log.Fatalln("Initial configuration directory error: %s", err.Error())
|
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 {
|
if err := hub.Parse(); err != nil {
|
||||||
log.Fatalln("Parse config error: %s", err.Error())
|
log.Fatalln("Parse config error: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue