github.com/klaytn/klaytn@v1.10.2/cmd/kspn/main.go (about)

     1  // Modifications Copyright 2019 The klaytn Authors
     2  // Copyright 2016 The go-ethereum Authors
     3  // This file is part of go-ethereum.
     4  //
     5  // go-ethereum is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // go-ethereum is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  // This file is derived from cmd/geth/main.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  package main
    22  
    23  import (
    24  	"fmt"
    25  	"os"
    26  	"sort"
    27  
    28  	"github.com/klaytn/klaytn/api/debug"
    29  	"github.com/klaytn/klaytn/cmd/utils"
    30  	"github.com/klaytn/klaytn/cmd/utils/nodecmd"
    31  	"github.com/klaytn/klaytn/console"
    32  	"github.com/klaytn/klaytn/log"
    33  	"gopkg.in/urfave/cli.v1"
    34  )
    35  
    36  var (
    37  	logger = log.NewModuleLogger(log.CMDKSPN)
    38  
    39  	// The app that holds all commands and flags.
    40  	app = utils.NewApp(nodecmd.GetGitCommit(), "The command line interface for Klaytn Proxy Node")
    41  )
    42  
    43  func init() {
    44  	utils.InitHelper()
    45  	// Initialize the CLI app and start kspn
    46  	app.Action = nodecmd.RunKlaytnNode
    47  	app.HideVersion = true // we have a command to print the version
    48  	app.Copyright = "Copyright 2018-2019 The klaytn Authors"
    49  	app.Commands = []cli.Command{
    50  		// See utils/nodecmd/chaincmd.go:
    51  		nodecmd.InitCommand,
    52  		nodecmd.DumpGenesisCommand,
    53  
    54  		// See utils/nodecmd/accountcmd.go
    55  		nodecmd.AccountCommand,
    56  
    57  		// See utils/nodecmd/consolecmd.go:
    58  		nodecmd.GetConsoleCommand(nodecmd.KspnNodeFlags(), nodecmd.CommonRPCFlags),
    59  		nodecmd.AttachCommand,
    60  
    61  		// See utils/nodecmd/versioncmd.go:
    62  		nodecmd.VersionCommand,
    63  
    64  		// See utils/nodecmd/dumpconfigcmd.go:
    65  		nodecmd.GetDumpConfigCommand(nodecmd.KspnNodeFlags(), nodecmd.CommonRPCFlags),
    66  
    67  		// See utils/nodecmd/snapshot.go:
    68  		nodecmd.SnapshotCommand,
    69  	}
    70  	sort.Sort(cli.CommandsByName(app.Commands))
    71  
    72  	app.Flags = nodecmd.KspnAppFlags()
    73  
    74  	cli.AppHelpTemplate = utils.GlobalAppHelpTemplate
    75  	cli.HelpPrinter = utils.NewHelpPrinter(utils.CategorizeFlags(app.Flags))
    76  
    77  	app.CommandNotFound = nodecmd.CommandNotExist
    78  	app.OnUsageError = nodecmd.OnUsageError
    79  	app.Before = nodecmd.BeforeRunNode
    80  	app.After = func(ctx *cli.Context) error {
    81  		debug.Exit()
    82  		console.Stdin.Close() // Resets terminal mode.
    83  		return nil
    84  	}
    85  }
    86  
    87  func main() {
    88  	// Set NodeTypeFlag to spn
    89  	utils.NodeTypeFlag.Value = "spn"
    90  
    91  	if err := app.Run(os.Args); err != nil {
    92  		fmt.Fprintln(os.Stderr, err)
    93  		os.Exit(1)
    94  	}
    95  }