mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
cmd/utils: reduce nesting levels a bit
This commit is contained in:
parent
642612cb9f
commit
a81accb08f
1 changed files with 28 additions and 18 deletions
|
|
@ -929,31 +929,41 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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{}) {
|
func checkExclusive(ctx *cli.Context, args ...interface{}) {
|
||||||
set := make([]string, 0, 1)
|
set := make([]string, 0, 1)
|
||||||
for i, arg := range args {
|
for i := 0; i < len(args); i++ {
|
||||||
if flag, ok := arg.(cli.Flag); ok {
|
// Make sure the next argument is a flag and skip if not set
|
||||||
if ctx.GlobalIsSet(flag.GetName()) {
|
flag, ok := args[i].(cli.Flag)
|
||||||
// Check if next arg extends current
|
if !ok {
|
||||||
if len(args) > i+1 {
|
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) {
|
switch option := args[i+1].(type) {
|
||||||
case cli.Flag:
|
|
||||||
set = append(set, `"--`+flag.GetName()+`"`)
|
|
||||||
case string:
|
case string:
|
||||||
|
// Extended flag, expand the name and shift the arguments
|
||||||
if ctx.GlobalString(flag.GetName()) == option {
|
if ctx.GlobalString(flag.GetName()) == option {
|
||||||
set = append(set, `"--`+flag.GetName()+` `+option+`"`)
|
name += "=" + option
|
||||||
}
|
}
|
||||||
|
i++
|
||||||
|
|
||||||
|
case cli.Flag:
|
||||||
default:
|
default:
|
||||||
Fatalf("Received wrong type in checkExclusive")
|
panic(fmt.Sprintf("invalid argument, not cli.Flag or string extension: %T", args[i+1]))
|
||||||
}
|
|
||||||
} else {
|
|
||||||
set = append(set, `"--`+flag.GetName()+`"`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Mark the flag if it's set
|
||||||
|
if ctx.GlobalIsSet(flag.GetName()) {
|
||||||
|
set = append(set, "--"+name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(set) > 1 {
|
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, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue