github.com/klaytn/klaytn@v1.12.1/cmd/utils/nodecmd/dumpconfigcmd.go (about)

     1  // Modifications Copyright 2018 The klaytn Authors
     2  // Copyright 2017 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/config.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  package nodecmd
    22  
    23  import (
    24  	"io"
    25  	"os"
    26  
    27  	"github.com/klaytn/klaytn/cmd/utils"
    28  	"github.com/urfave/cli/v2"
    29  )
    30  
    31  // GetDumpConfigCommand returns cli.Command `dumpconfig` whose flags are initialized with nodeFlags and rpcFlags.
    32  func GetDumpConfigCommand(nodeFlags, rpcFlags []cli.Flag) *cli.Command {
    33  	return &cli.Command{
    34  		Action:      dumpConfig,
    35  		Name:        "dumpconfig",
    36  		Usage:       "Show configuration values",
    37  		ArgsUsage:   "",
    38  		Flags:       append(append(nodeFlags, rpcFlags...)),
    39  		Category:    "MISCELLANEOUS COMMANDS",
    40  		Description: `The dumpconfig command shows configuration values.`,
    41  	}
    42  }
    43  
    44  func dumpConfig(ctx *cli.Context) error {
    45  	_, cfg := utils.MakeConfigNode(ctx)
    46  	comment := ""
    47  
    48  	if cfg.CN.Genesis != nil {
    49  		cfg.CN.Genesis = nil
    50  		comment += "# Note: this config doesn't contain the genesis block.\n\n"
    51  	}
    52  	if cfg.ChainDataFetcher.KafkaConfig != nil {
    53  		cfg.ChainDataFetcher.KafkaConfig = nil
    54  		comment += "# Note: this config doesn't contain the Kafka configuration.\n\n"
    55  	}
    56  
    57  	out, err := utils.TomlSettings.Marshal(&cfg)
    58  	if err != nil {
    59  		return err
    60  	}
    61  	io.WriteString(os.Stdout, comment)
    62  	os.Stdout.Write(out)
    63  	return nil
    64  }