github.com/klaytn/klaytn@v1.12.1/cmd/kcn/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  	"github.com/urfave/cli/v2"
    34  )
    35  
    36  var (
    37  	logger = log.NewModuleLogger(log.CMDKCN)
    38  
    39  	// The app that holds all commands and flags.
    40  	app = utils.NewApp(nodecmd.GetGitCommit(), "The command line interface for Klaytn Consensus Node")
    41  )
    42  
    43  func init() {
    44  	// Initialize the CLI app and start kcn
    45  	app.Action = nodecmd.RunKlaytnNode
    46  	app.HideVersion = true // we have a command to print the version
    47  	app.Copyright = "Copyright 2018-2023 The klaytn Authors"
    48  	app.Commands = []*cli.Command{
    49  		// See utils/nodecmd/chaincmd.go:
    50  		nodecmd.InitCommand,
    51  		nodecmd.DumpGenesisCommand,
    52  
    53  		// See utils/nodecmd/accountcmd.go
    54  		nodecmd.AccountCommand,
    55  
    56  		// See utils/nodecmd/consolecmd.go:
    57  		nodecmd.GetConsoleCommand(utils.KcnNodeFlags(), utils.CommonRPCFlags),
    58  		nodecmd.AttachCommand,
    59  
    60  		// See utils/nodecmd/versioncmd.go:
    61  		nodecmd.VersionCommand,
    62  
    63  		// See utils/nodecmd/dumpconfigcmd.go:
    64  		nodecmd.GetDumpConfigCommand(utils.KcnNodeFlags(), utils.CommonRPCFlags),
    65  
    66  		// See utils/nodecmd/db_migration.go:
    67  		nodecmd.MigrationCommand,
    68  
    69  		// See utils/nodecmd/util.go:
    70  		nodecmd.UtilCommand,
    71  
    72  		// See utils/nodecmd/snapshot.go:
    73  		nodecmd.SnapshotCommand,
    74  	}
    75  	sort.Sort(cli.CommandsByName(app.Commands))
    76  
    77  	app.Flags = utils.KcnAppFlags()
    78  
    79  	app.CommandNotFound = nodecmd.CommandNotExist
    80  	app.OnUsageError = nodecmd.OnUsageError
    81  	app.Before = nodecmd.BeforeRunNode
    82  	app.After = func(ctx *cli.Context) error {
    83  		debug.Exit()
    84  		console.Stdin.Close() // Resets terminal mode.
    85  		return nil
    86  	}
    87  }
    88  
    89  func main() {
    90  	// Set NodeTypeFlag to cn
    91  	utils.NodeTypeFlag.Value = "cn"
    92  
    93  	if err := app.Run(os.Args); err != nil {
    94  		fmt.Fprintln(os.Stderr, err)
    95  		os.Exit(1)
    96  	}
    97  }