github.com/klaytn/klaytn@v1.12.1/cmd/ksen/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  	"github.com/urfave/cli/v2"
    34  )
    35  
    36  var (
    37  	logger = log.NewModuleLogger(log.CMDKSEN)
    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  	// Initialize the CLI app and start ksen
    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.KsenNodeFlags(), 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.KsenNodeFlags(), utils.CommonRPCFlags),
    65  
    66  		// See utils/nodecmd/util.go:
    67  		nodecmd.UtilCommand,
    68  
    69  		// See utils/nodecmd/snapshot.go:
    70  		nodecmd.SnapshotCommand,
    71  	}
    72  	sort.Sort(cli.CommandsByName(app.Commands))
    73  
    74  	app.Flags = utils.KsenAppFlags()
    75  
    76  	app.CommandNotFound = nodecmd.CommandNotExist
    77  	app.OnUsageError = nodecmd.OnUsageError
    78  	app.Before = nodecmd.BeforeRunNode
    79  	app.After = func(ctx *cli.Context) error {
    80  		debug.Exit()
    81  		console.Stdin.Close() // Resets terminal mode.
    82  		return nil
    83  	}
    84  }
    85  
    86  func main() {
    87  	// Set NodeTypeFlag to sen
    88  	utils.NodeTypeFlag.Value = "sen"
    89  
    90  	if err := app.Run(os.Args); err != nil {
    91  		fmt.Fprintln(os.Stderr, err)
    92  		os.Exit(1)
    93  	}
    94  }