Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Sep 25, 2023
1 parent d2073c5 commit faab519
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"math"
"os"
Expand Down Expand Up @@ -1170,7 +1171,7 @@ func isAllRemovedConfigItems(items []string) bool {
// The function enforceCmdArgs is used to merge the config file with command arguments:
// For example, if you start TiDB by the command "./tidb-server --port=3000", the port number should be
// overwritten to 3000 and ignore the port number in the config file.
func InitializeConfig(confPath string, configCheck, configStrict bool, enforceCmdArgs func(*Config)) {
func InitializeConfig(confPath string, configCheck, configStrict bool, enforceCmdArgs func(*Config, fset *flag.FlagSet), fset *flag.FlagSet) {
cfg := GetGlobalConfig()
var err error
if confPath != "" {
Expand Down Expand Up @@ -1208,7 +1209,7 @@ func InitializeConfig(confPath string, configCheck, configStrict bool, enforceCm
os.Exit(1)
}
}
enforceCmdArgs(cfg)
enforceCmdArgs(cfg, fset)

if err := cfg.Valid(); err != nil {
if !filepath.IsAbs(confPath) {
Expand Down
15 changes: 8 additions & 7 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var (
help *bool
)

func initflag() {
func initflag() *flag.FlagSet {
fset := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
version = flagBoolean(fset, nmVersion, false, "print version information and exit")
configPath = fset.String(nmConfig, "", "config file path")
Expand Down Expand Up @@ -243,11 +243,12 @@ func initflag() {
fset.Usage()
os.Exit(0)
}
return fset
}

func main() {
initflag()
config.InitializeConfig(*configPath, *configCheck, *configStrict, overrideConfig)
fset := initflag()
config.InitializeConfig(*configPath, *configCheck, *configStrict, overrideConfig, fset)
if *version {
setVersions()
fmt.Println(printer.GetTiDBInfo())
Expand Down Expand Up @@ -491,15 +492,15 @@ func flagBoolean(fset *flag.FlagSet, name string, defaultVal bool, usage string)
if !defaultVal {
// Fix #4125, golang do not print default false value in usage, so we append it.
usage = fmt.Sprintf("%s (default false)", usage)
return flag.Bool(name, defaultVal, usage)
return fset.Bool(name, defaultVal, usage)
}
return flag.Bool(name, defaultVal, usage)
return fset.Bool(name, defaultVal, usage)
}

// overrideConfig considers command arguments and overrides some config items in the Config.
func overrideConfig(cfg *config.Config) {
func overrideConfig(cfg *config.Config, fset *flag.FlagSet) {
actualFlags := make(map[string]bool)
flag.Visit(func(f *flag.Flag) {
fset.Visit(func(f *flag.Flag) {
actualFlags[f.Name] = true
})

Expand Down

0 comments on commit faab519

Please sign in to comment.