Feature: add more command-line options (#656)
add command-line options to override `external-controller`, `secret` and `external-ui` (#531)
This commit is contained in:
27
hub/hub.go
27
hub/hub.go
@ -3,15 +3,40 @@ package hub
|
||||
import (
|
||||
"github.com/Dreamacro/clash/hub/executor"
|
||||
"github.com/Dreamacro/clash/hub/route"
|
||||
"github.com/Dreamacro/clash/config"
|
||||
)
|
||||
|
||||
type Option func(*config.Config)
|
||||
|
||||
func WithExternalUI(externalUI string) Option {
|
||||
return func(cfg *config.Config) {
|
||||
cfg.General.ExternalUI = externalUI
|
||||
}
|
||||
}
|
||||
|
||||
func WithExternalController(externalController string) Option {
|
||||
return func(cfg *config.Config) {
|
||||
cfg.General.ExternalController = externalController
|
||||
}
|
||||
}
|
||||
|
||||
func WithSecret(secret string) Option {
|
||||
return func(cfg *config.Config) {
|
||||
cfg.General.Secret = secret
|
||||
}
|
||||
}
|
||||
|
||||
// Parse call at the beginning of clash
|
||||
func Parse() error {
|
||||
func Parse(options ...Option) error {
|
||||
cfg, err := executor.Parse()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
option(cfg)
|
||||
}
|
||||
|
||||
if cfg.General.ExternalUI != "" {
|
||||
route.SetUIPath(cfg.General.ExternalUI)
|
||||
}
|
||||
|
Reference in New Issue
Block a user