feature: add environs startup option support (#2909)

This commit is contained in:
septs 2023-10-16 09:22:16 +08:00 committed by wwqgtxx
parent 81bbbe4eec
commit 98df77439c

22
main.go
View file

@ -21,7 +21,6 @@ import (
) )
var ( var (
flagset map[string]bool
version bool version bool
testConfig bool testConfig bool
geodataMode bool geodataMode bool
@ -33,20 +32,15 @@ var (
) )
func init() { func init() {
flag.StringVar(&homeDir, "d", "", "set configuration directory") flag.StringVar(&homeDir, "d", os.Getenv("CLASH_HOME_DIR"), "set configuration directory")
flag.StringVar(&configFile, "f", "", "specify configuration file") flag.StringVar(&configFile, "f", os.Getenv("CLASH_CONFIG_FILE"), "specify configuration file")
flag.StringVar(&externalUI, "ext-ui", "", "override external ui directory") flag.StringVar(&externalUI, "ext-ui", os.Getenv("CLASH_OVERRIDE_EXTERNAL_UI_DIR"), "override external ui directory")
flag.StringVar(&externalController, "ext-ctl", "", "override external controller address") flag.StringVar(&externalController, "ext-ctl", os.Getenv("CLASH_OVERRIDE_EXTERNAL_CONTROLLER"), "override external controller address")
flag.StringVar(&secret, "secret", "", "override secret for RESTful API") flag.StringVar(&secret, "secret", os.Getenv("CLASH_OVERRIDE_SECRET"), "override secret for RESTful API")
flag.BoolVar(&geodataMode, "m", false, "set geodata mode") flag.BoolVar(&geodataMode, "m", false, "set geodata mode")
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.BoolVar(&testConfig, "t", false, "test configuration and exit")
flag.Parse() flag.Parse()
flagset = map[string]bool{}
flag.Visit(func(f *flag.Flag) {
flagset[f.Name] = true
})
} }
func main() { func main() {
@ -99,13 +93,13 @@ func main() {
} }
var options []hub.Option var options []hub.Option
if flagset["ext-ui"] { if externalUI != "" {
options = append(options, hub.WithExternalUI(externalUI)) options = append(options, hub.WithExternalUI(externalUI))
} }
if flagset["ext-ctl"] { if externalController != "" {
options = append(options, hub.WithExternalController(externalController)) options = append(options, hub.WithExternalController(externalController))
} }
if flagset["secret"] { if secret != "" {
options = append(options, hub.WithSecret(secret)) options = append(options, hub.WithSecret(secret))
} }