mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
cmd/geth, cmd/utils, cmd/workload: respect explicit false bool flags
This commit is contained in:
parent
5abf1161f2
commit
c6065f2d0b
5 changed files with 61 additions and 9 deletions
|
|
@ -794,8 +794,8 @@ func downloadEra(ctx *cli.Context) error {
|
||||||
var network = "mainnet"
|
var network = "mainnet"
|
||||||
if utils.IsNetworkPreset(ctx) {
|
if utils.IsNetworkPreset(ctx) {
|
||||||
switch {
|
switch {
|
||||||
case ctx.IsSet(utils.MainnetFlag.Name):
|
case ctx.Bool(utils.MainnetFlag.Name):
|
||||||
case ctx.IsSet(utils.SepoliaFlag.Name):
|
case ctx.Bool(utils.SepoliaFlag.Name):
|
||||||
network = "sepolia"
|
network = "sepolia"
|
||||||
default:
|
default:
|
||||||
return errors.New("unsupported network, no known era1 checksums")
|
return errors.New("unsupported network, no known era1 checksums")
|
||||||
|
|
@ -822,7 +822,7 @@ func downloadEra(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case ctx.IsSet(eraAllFlag.Name):
|
case ctx.Bool(eraAllFlag.Name):
|
||||||
return l.DownloadAll(dir)
|
return l.DownloadAll(dir)
|
||||||
|
|
||||||
case ctx.IsSet(eraBlockFlag.Name):
|
case ctx.IsSet(eraBlockFlag.Name):
|
||||||
|
|
|
||||||
|
|
@ -303,13 +303,13 @@ func main() {
|
||||||
func prepare(ctx *cli.Context) {
|
func prepare(ctx *cli.Context) {
|
||||||
// If we're running a known preset, log it for convenience.
|
// If we're running a known preset, log it for convenience.
|
||||||
switch {
|
switch {
|
||||||
case ctx.IsSet(utils.SepoliaFlag.Name):
|
case ctx.Bool(utils.SepoliaFlag.Name):
|
||||||
log.Info("Starting Geth on Sepolia testnet...")
|
log.Info("Starting Geth on Sepolia testnet...")
|
||||||
|
|
||||||
case ctx.IsSet(utils.HoleskyFlag.Name):
|
case ctx.Bool(utils.HoleskyFlag.Name):
|
||||||
log.Info("Starting Geth on Holesky testnet...")
|
log.Info("Starting Geth on Holesky testnet...")
|
||||||
|
|
||||||
case ctx.IsSet(utils.HoodiFlag.Name):
|
case ctx.Bool(utils.HoodiFlag.Name):
|
||||||
log.Info("Starting Geth on Hoodi testnet...")
|
log.Info("Starting Geth on Hoodi testnet...")
|
||||||
|
|
||||||
case !ctx.IsSet(utils.NetworkIdFlag.Name):
|
case !ctx.IsSet(utils.NetworkIdFlag.Name):
|
||||||
|
|
|
||||||
|
|
@ -1926,7 +1926,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
if ctx.IsSet(RPCGlobalTxFeeCapFlag.Name) {
|
if ctx.IsSet(RPCGlobalTxFeeCapFlag.Name) {
|
||||||
cfg.RPCTxFeeCap = ctx.Float64(RPCGlobalTxFeeCapFlag.Name)
|
cfg.RPCTxFeeCap = ctx.Float64(RPCGlobalTxFeeCapFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.IsSet(NoDiscoverFlag.Name) {
|
if ctx.Bool(NoDiscoverFlag.Name) {
|
||||||
cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs = []string{}, []string{}
|
cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs = []string{}, []string{}
|
||||||
} else if ctx.IsSet(DNSDiscoveryFlag.Name) {
|
} else if ctx.IsSet(DNSDiscoveryFlag.Name) {
|
||||||
urls := ctx.String(DNSDiscoveryFlag.Name)
|
urls := ctx.String(DNSDiscoveryFlag.Name)
|
||||||
|
|
@ -2361,7 +2361,7 @@ func tryMakeReadOnlyDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database
|
||||||
func IsNetworkPreset(ctx *cli.Context) bool {
|
func IsNetworkPreset(ctx *cli.Context) bool {
|
||||||
for _, flag := range NetworkFlags {
|
for _, flag := range NetworkFlags {
|
||||||
bFlag, _ := flag.(*cli.BoolFlag)
|
bFlag, _ := flag.(*cli.BoolFlag)
|
||||||
if ctx.IsSet(bFlag.Name) {
|
if ctx.Bool(bFlag.Name) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,11 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_SplitTagsFlag(t *testing.T) {
|
func Test_SplitTagsFlag(t *testing.T) {
|
||||||
|
|
@ -64,3 +67,52 @@ func Test_SplitTagsFlag(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsNetworkPresetUsesFlagValue(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "unset",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "enabled",
|
||||||
|
args: []string{"--sepolia"},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "explicit false",
|
||||||
|
args: []string{"--sepolia=false"},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
ctx := newTestContext(t, tt.args, NetworkFlags...)
|
||||||
|
if got := IsNetworkPreset(ctx); got != tt.want {
|
||||||
|
t.Fatalf("IsNetworkPreset() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestContext(t *testing.T, args []string, flags ...cli.Flag) *cli.Context {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
set := flag.NewFlagSet("test", flag.ContinueOnError)
|
||||||
|
for _, f := range flags {
|
||||||
|
if err := f.Apply(set); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := set.Parse(args); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return cli.NewContext(nil, set, nil)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ func validateHistoryPruneErr(err error, blockNum uint64, historyPruneBlock *uint
|
||||||
|
|
||||||
func testConfigFromCLI(ctx *cli.Context) (cfg testConfig) {
|
func testConfigFromCLI(ctx *cli.Context) (cfg testConfig) {
|
||||||
flags.CheckExclusive(ctx, testMainnetFlag, testSepoliaFlag)
|
flags.CheckExclusive(ctx, testMainnetFlag, testSepoliaFlag)
|
||||||
if (ctx.IsSet(testMainnetFlag.Name) || ctx.IsSet(testSepoliaFlag.Name)) && ctx.IsSet(filterQueryFileFlag.Name) {
|
if (ctx.Bool(testMainnetFlag.Name) || ctx.Bool(testSepoliaFlag.Name)) && ctx.IsSet(filterQueryFileFlag.Name) {
|
||||||
exit(filterQueryFileFlag.Name + " cannot be used with " + testMainnetFlag.Name + " or " + testSepoliaFlag.Name)
|
exit(filterQueryFileFlag.Name + " cannot be used with " + testMainnetFlag.Name + " or " + testSepoliaFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue