mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 10:20:44 +00:00
cmd/XDC, internal/flags: print envvar config source and bad names (#28119)
This commit is contained in:
parent
87ddf502ce
commit
4e192a5172
2 changed files with 37 additions and 0 deletions
|
|
@ -201,6 +201,7 @@ func init() {
|
||||||
if err := debug.Setup(ctx); err != nil {
|
if err := debug.Setup(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
flags.CheckEnvVars(ctx, app.Flags, "XDC")
|
||||||
// Start system runtime metrics collection
|
// Start system runtime metrics collection
|
||||||
go metrics.CollectProcessMetrics(3 * time.Second)
|
go metrics.CollectProcessMetrics(3 * time.Second)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
@ -252,3 +254,37 @@ func AutoEnvVars(flags []cli.Flag, prefix string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckEnvVars iterates over all the environment variables and checks if any of
|
||||||
|
// them look like a CLI flag but is not consumed. This can be used to detect old
|
||||||
|
// or mistyped names.
|
||||||
|
func CheckEnvVars(ctx *cli.Context, flags []cli.Flag, prefix string) {
|
||||||
|
known := make(map[string]string)
|
||||||
|
for _, flag := range flags {
|
||||||
|
docflag, ok := flag.(cli.DocGenerationFlag)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, envvar := range docflag.GetEnvVars() {
|
||||||
|
known[envvar] = flag.Names()[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keyvals := os.Environ()
|
||||||
|
sort.Strings(keyvals)
|
||||||
|
|
||||||
|
for _, keyval := range keyvals {
|
||||||
|
key := strings.Split(keyval, "=")[0]
|
||||||
|
if !strings.HasPrefix(key, prefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if flag, ok := known[key]; ok {
|
||||||
|
if ctx.Count(flag) > 0 {
|
||||||
|
log.Info("Config environment variable found", "envvar", key, "shadowedby", "--"+flag)
|
||||||
|
} else {
|
||||||
|
log.Info("Config environment variable found", "envvar", key)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Warn("Unknown config environment variable", "envvar", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue