github.com/theQRL/go-zond@v0.1.1/cmd/devp2p/main.go (about) 1 // Copyright 2019 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "fmt" 21 "os" 22 23 "github.com/theQRL/go-zond/internal/debug" 24 "github.com/theQRL/go-zond/internal/flags" 25 "github.com/theQRL/go-zond/p2p/enode" 26 "github.com/urfave/cli/v2" 27 ) 28 29 var app = flags.NewApp("go-ethereum devp2p tool") 30 31 func init() { 32 app.Flags = append(app.Flags, debug.Flags...) 33 app.Before = func(ctx *cli.Context) error { 34 flags.MigrateGlobalFlags(ctx) 35 return debug.Setup(ctx) 36 } 37 app.After = func(ctx *cli.Context) error { 38 debug.Exit() 39 return nil 40 } 41 app.CommandNotFound = func(ctx *cli.Context, cmd string) { 42 fmt.Fprintf(os.Stderr, "No such command: %s\n", cmd) 43 os.Exit(1) 44 } 45 46 // Add subcommands. 47 app.Commands = []*cli.Command{ 48 enrdumpCommand, 49 keyCommand, 50 discv4Command, 51 discv5Command, 52 dnsCommand, 53 nodesetCommand, 54 rlpxCommand, 55 } 56 } 57 58 func main() { 59 exit(app.Run(os.Args)) 60 } 61 62 // commandHasFlag returns true if the current command supports the given flag. 63 func commandHasFlag(ctx *cli.Context, flag cli.Flag) bool { 64 names := flag.Names() 65 set := make(map[string]struct{}, len(names)) 66 for _, name := range names { 67 set[name] = struct{}{} 68 } 69 for _, fn := range ctx.FlagNames() { 70 if _, ok := set[fn]; ok { 71 return true 72 } 73 } 74 return false 75 } 76 77 // getNodeArg handles the common case of a single node descriptor argument. 78 func getNodeArg(ctx *cli.Context) *enode.Node { 79 if ctx.NArg() < 1 { 80 exit("missing node as command-line argument") 81 } 82 n, err := parseNode(ctx.Args().First()) 83 if err != nil { 84 exit(err) 85 } 86 return n 87 } 88 89 func exit(err interface{}) { 90 if err == nil { 91 os.Exit(0) 92 } 93 fmt.Fprintln(os.Stderr, err) 94 os.Exit(1) 95 }