diff options
author | Paul Litvak <litvakpol@012.net.il> | 2017-11-24 23:07:22 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-11-24 23:07:21 +0800 |
commit | e4c9fd29a3907367b2b6b7cd32b0098350a94741 (patch) | |
tree | 722c7a6b352bb7a7f1ba447962bbadcf7d41e7ad /cmd | |
parent | de37e088f2f317d900c84166b2f3e2aee7173595 (diff) | |
download | go-tangerine-e4c9fd29a3907367b2b6b7cd32b0098350a94741.tar go-tangerine-e4c9fd29a3907367b2b6b7cd32b0098350a94741.tar.gz go-tangerine-e4c9fd29a3907367b2b6b7cd32b0098350a94741.tar.bz2 go-tangerine-e4c9fd29a3907367b2b6b7cd32b0098350a94741.tar.lz go-tangerine-e4c9fd29a3907367b2b6b7cd32b0098350a94741.tar.xz go-tangerine-e4c9fd29a3907367b2b6b7cd32b0098350a94741.tar.zst go-tangerine-e4c9fd29a3907367b2b6b7cd32b0098350a94741.zip |
cmd/utils: disallow --lightserv in light mode (#15514)
* Disallow --lightserv in light mode
* Reformatted
* cmd/utils: reduce nesting levels a bit
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/utils/flags.go | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9fbad8dab..0c89d9a4c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -929,15 +929,41 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) { } } -func checkExclusive(ctx *cli.Context, flags ...cli.Flag) { +// checkExclusive verifies that only a single isntance of the provided flags was +// set by the user. Each flag might optionally be followed by a string type to +// specialize it further. +func checkExclusive(ctx *cli.Context, args ...interface{}) { set := make([]string, 0, 1) - for _, flag := range flags { + for i := 0; i < len(args); i++ { + // Make sure the next argument is a flag and skip if not set + flag, ok := args[i].(cli.Flag) + if !ok { + panic(fmt.Sprintf("invalid argument, not cli.Flag type: %T", args[i])) + } + // Check if next arg extends current and expand its name if so + name := flag.GetName() + + if i+1 < len(args) { + switch option := args[i+1].(type) { + case string: + // Extended flag, expand the name and shift the arguments + if ctx.GlobalString(flag.GetName()) == option { + name += "=" + option + } + i++ + + case cli.Flag: + default: + panic(fmt.Sprintf("invalid argument, not cli.Flag or string extension: %T", args[i+1])) + } + } + // Mark the flag if it's set if ctx.GlobalIsSet(flag.GetName()) { - set = append(set, "--"+flag.GetName()) + set = append(set, "--"+name) } } if len(set) > 1 { - Fatalf("flags %v can't be used at the same time", strings.Join(set, ", ")) + Fatalf("Flags %v can't be used at the same time", strings.Join(set, ", ")) } } @@ -956,6 +982,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { // Avoid conflicting network flags checkExclusive(ctx, DeveloperFlag, TestnetFlag, RinkebyFlag) checkExclusive(ctx, FastSyncFlag, LightModeFlag, SyncModeFlag) + checkExclusive(ctx, LightServFlag, LightModeFlag) + checkExclusive(ctx, LightServFlag, SyncModeFlag, "light") ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) setEtherbase(ctx, ks, cfg) |