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

     1  // Modifications Copyright 2018 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.CMDKEN)
    38  
    39  	// The app that holds all commands and flags.
    40  	app = utils.NewApp(nodecmd.GetGitCommit(), "The command line interface for Klaytn Endpoint Node")
    41  )
    42  
    43  func init() {
    44  	utils.InitHelper()
    45  	// Initialize the CLI app and start ken
    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.KenNodeFlags(), 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.KenNodeFlags(), nodecmd.CommonRPCFlags),
    66  
    67  		// See utils/nodecmd/db_migration.go:
    68  		nodecmd.MigrationCommand,
    69  
    70  		// See utils/nodecmd/snapshot.go:
    71  		nodecmd.SnapshotCommand,
    72  	}
    73  	sort.Sort(cli.CommandsByName(app.Commands))
    74  
    75  	app.Flags = nodecmd.KenAppFlags()
    76  
    77  	cli.AppHelpTemplate = utils.GlobalAppHelpTemplate
    78  	cli.HelpPrinter = utils.NewHelpPrinter(utils.CategorizeFlags(app.Flags))
    79  
    80  	app.CommandNotFound = nodecmd.CommandNotExist
    81  	app.OnUsageError = nodecmd.OnUsageError
    82  	app.Before = nodecmd.BeforeRunNode
    83  	app.After = func(ctx *cli.Context) error {
    84  		debug.Exit()
    85  		console.Stdin.Close() // Resets terminal mode.
    86  		return nil
    87  	}
    88  }
    89  
    90  func main() {
    91  	// Set NodeTypeFlag to en
    92  	utils.NodeTypeFlag.Value = "en"
    93  
    94  	if err := app.Run(os.Args); err != nil {
    95  		fmt.Fprintln(os.Stderr, err)
    96  		os.Exit(1)
    97  	}
    98  }