Skip to content

Commit

Permalink
feat: support -ext-ctl-unix cmdline to override external controller…
Browse files Browse the repository at this point in the history
… unix address
  • Loading branch information
wwqgtxx committed Apr 17, 2024
1 parent 458b29b commit 933278b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions hub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func WithExternalController(externalController string) Option {
}
}

func WithExternalControllerUnix(externalControllerUnix string) Option {
return func(cfg *config.Config) {
cfg.General.ExternalControllerUnix = externalControllerUnix
}
}

func WithSecret(secret string) Option {
return func(cfg *config.Config) {
cfg.General.Secret = secret
Expand Down
19 changes: 12 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ import (
)

var (
version bool
testConfig bool
homeDir string
configFile string
externalUI string
externalController string
secret string
version bool
testConfig bool
homeDir string
configFile string
externalUI string
externalController string
externalControllerUnix string
secret string
)

func init() {
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(&externalControllerUnix, "ext-ctl-unix", os.Getenv("CLASH_OVERRIDE_EXTERNAL_CONTROLLER_UNIX"), "override external controller unix address")
flag.StringVar(&secret, "secret", os.Getenv("CLASH_OVERRIDE_SECRET"), "override secret for RESTful API")
flag.BoolVar(&version, "v", false, "show current version of mihomo")
flag.BoolVar(&testConfig, "t", false, "test configuration and exit")
Expand Down Expand Up @@ -92,6 +94,9 @@ func main() {
if externalController != "" {
options = append(options, hub.WithExternalController(externalController))
}
if externalControllerUnix != "" {
options = append(options, hub.WithExternalControllerUnix(externalControllerUnix))
}
if secret != "" {
options = append(options, hub.WithSecret(secret))
}
Expand Down

0 comments on commit 933278b

Please sign in to comment.