1
0

Feature: add environs startup option support (#2909)

This commit is contained in:
septs 2023-08-28 21:05:01 +08:00 committed by GitHub
parent e4cd3e5306
commit 0450860eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

22
main.go
View File

@ -19,7 +19,6 @@ import (
)
var (
flagset map[string]bool
version bool
testConfig bool
homeDir string
@ -30,19 +29,14 @@ var (
)
func init() {
flag.StringVar(&homeDir, "d", "", "set configuration directory")
flag.StringVar(&configFile, "f", "", "specify configuration file")
flag.StringVar(&externalUI, "ext-ui", "", "override external ui directory")
flag.StringVar(&externalController, "ext-ctl", "", "override external controller address")
flag.StringVar(&secret, "secret", "", "override secret for RESTful API")
flag.StringVar(&homeDir, "d", os.Getenv("CLASH_HOME_DIR"), "set configuration directory")
flag.StringVar(&configFile, "f", os.Getenv("CLASH_CONFIG_FILE"), "specify configuration file")
flag.StringVar(&externalUI, "ext-ui", os.Getenv("CLASH_OVERRIDE_EXTERNAL_UI_DIR"), "override external ui directory")
flag.StringVar(&externalController, "ext-ctl", os.Getenv("CLASH_OVERRIDE_EXTERNAL_CONTROLLER"), "override external controller address")
flag.StringVar(&secret, "secret", os.Getenv("CLASH_OVERRIDE_SECRET"), "override secret for RESTful API")
flag.BoolVar(&version, "v", false, "show current version of clash")
flag.BoolVar(&testConfig, "t", false, "test configuration and exit")
flag.Parse()
flagset = map[string]bool{}
flag.Visit(func(f *flag.Flag) {
flagset[f.Name] = true
})
}
func main() {
@ -86,13 +80,13 @@ func main() {
}
var options []hub.Option
if flagset["ext-ui"] {
if externalUI != "" {
options = append(options, hub.WithExternalUI(externalUI))
}
if flagset["ext-ctl"] {
if externalController != "" {
options = append(options, hub.WithExternalController(externalController))
}
if flagset["secret"] {
if secret != "" {
options = append(options, hub.WithSecret(secret))
}