Skip to content

Commit

Permalink
cmd/utils: disallow --lightserv in light mode (ethereum#15514)
Browse files Browse the repository at this point in the history
* Disallow --lightserv in light mode

* Reformatted

* cmd/utils: reduce nesting levels a bit
  • Loading branch information
Paul Litvak authored and karalabe committed Nov 24, 2017
1 parent de37e08 commit e4c9fd2
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ", "))
}
}

Expand All @@ -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)
Expand Down

0 comments on commit e4c9fd2

Please sign in to comment.