github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/cmd/peer/main.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package main
     8  
     9  import (
    10  	_ "net/http/pprof"
    11  	"os"
    12  	"strings"
    13  
    14  	"github.com/hechain20/hechain/bccsp/factory"
    15  	"github.com/hechain20/hechain/internal/peer/chaincode"
    16  	"github.com/hechain20/hechain/internal/peer/channel"
    17  	"github.com/hechain20/hechain/internal/peer/common"
    18  	"github.com/hechain20/hechain/internal/peer/lifecycle"
    19  	"github.com/hechain20/hechain/internal/peer/node"
    20  	"github.com/hechain20/hechain/internal/peer/snapshot"
    21  	"github.com/hechain20/hechain/internal/peer/version"
    22  	"github.com/spf13/cobra"
    23  	"github.com/spf13/viper"
    24  )
    25  
    26  // The main command describes the service and
    27  // defaults to printing the help message.
    28  var mainCmd = &cobra.Command{Use: "peer"}
    29  
    30  func main() {
    31  	// For environment variables.
    32  	viper.SetEnvPrefix(common.CmdRoot)
    33  	viper.AutomaticEnv()
    34  	replacer := strings.NewReplacer(".", "_")
    35  	viper.SetEnvKeyReplacer(replacer)
    36  
    37  	// Define command-line flags that are valid for all peer commands and
    38  	// subcommands.
    39  	mainFlags := mainCmd.PersistentFlags()
    40  
    41  	mainFlags.String("logging-level", "", "Legacy logging level flag")
    42  	viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
    43  	mainFlags.MarkHidden("logging-level")
    44  
    45  	cryptoProvider := factory.GetDefault()
    46  
    47  	mainCmd.AddCommand(version.Cmd())
    48  	mainCmd.AddCommand(node.Cmd())
    49  	mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider))
    50  	mainCmd.AddCommand(channel.Cmd(nil))
    51  	mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider))
    52  	mainCmd.AddCommand(snapshot.Cmd(cryptoProvider))
    53  
    54  	// On failure Cobra prints the usage message and error string, so we only
    55  	// need to exit with a non-0 status
    56  	if mainCmd.Execute() != nil {
    57  		os.Exit(1)
    58  	}
    59  }