cmd/geth: add --noenv to disable the use of environment variables

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-09-28 08:39:50 +00:00
parent 37a2d919b0
commit f16de081d3
2 changed files with 24 additions and 2 deletions

View file

@ -242,8 +242,22 @@ func init() {
consoleFlags, consoleFlags,
debug.Flags, debug.Flags,
metricsFlags, metricsFlags,
[]cli.Flag{utils.NoEnvironmentFlag},
) )
flags.AutoEnvVars(app.Flags, "GETH")
noenv := false
for _, arg := range os.Args {
flag := strings.TrimLeft(arg, "-")
if flag == utils.NoEnvironmentFlag.Name {
log.Info("Disables the use of environment variables for configuration")
noenv = true
break
}
}
if !noenv {
flags.AutoEnvVars(app.Flags, "GETH")
}
app.Before = func(ctx *cli.Context) error { app.Before = func(ctx *cli.Context) error {
maxprocs.Set() // Automatically set GOMAXPROCS to match Linux container CPU quota. maxprocs.Set() // Automatically set GOMAXPROCS to match Linux container CPU quota.
@ -251,7 +265,9 @@ 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, "GETH") if !noenv {
flags.CheckEnvVars(ctx, app.Flags, "GETH")
}
return nil return nil
} }
app.After = func(ctx *cli.Context) error { app.After = func(ctx *cli.Context) error {

View file

@ -949,6 +949,12 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Value: metrics.DefaultConfig.InfluxDBOrganization, Value: metrics.DefaultConfig.InfluxDBOrganization,
Category: flags.MetricsCategory, Category: flags.MetricsCategory,
} }
NoEnvironmentFlag = &cli.BoolFlag{
Name: "noenv",
Usage: "Disables the use of environment variables for configuration",
Category: flags.MiscCategory,
}
) )
var ( var (