main.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. package main
  17. import (
  18. "fmt"
  19. "os"
  20. "path/filepath"
  21. "github.com/ethereum/go-ethereum/internal/debug"
  22. "github.com/ethereum/go-ethereum/params"
  23. "gopkg.in/urfave/cli.v1"
  24. )
  25. var (
  26. // Git information set by linker when building with ci.go.
  27. gitCommit string
  28. gitDate string
  29. app = &cli.App{
  30. Name: filepath.Base(os.Args[0]),
  31. Usage: "go-ethereum devp2p tool",
  32. Version: params.VersionWithCommit(gitCommit, gitDate),
  33. Writer: os.Stdout,
  34. HideVersion: true,
  35. }
  36. )
  37. func init() {
  38. // Set up the CLI app.
  39. app.Flags = append(app.Flags, debug.Flags...)
  40. app.Before = func(ctx *cli.Context) error {
  41. return debug.Setup(ctx, "")
  42. }
  43. app.After = func(ctx *cli.Context) error {
  44. debug.Exit()
  45. return nil
  46. }
  47. app.CommandNotFound = func(ctx *cli.Context, cmd string) {
  48. fmt.Fprintf(os.Stderr, "No such command: %s\n", cmd)
  49. os.Exit(1)
  50. }
  51. // Add subcommands.
  52. app.Commands = []cli.Command{
  53. enrdumpCommand,
  54. discv4Command,
  55. }
  56. }
  57. func main() {
  58. if err := app.Run(os.Args); err != nil {
  59. fmt.Fprintln(os.Stderr, err)
  60. os.Exit(1)
  61. }
  62. }