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