github.com/Hnampk/fabric@v2.1.1+incompatible/cmd/peer/main.go (about)

     1  /*
     2  Copyright IBM Corp. 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/hyperledger/fabric/bccsp/factory"
    15  	"github.com/hyperledger/fabric/internal/peer/chaincode"
    16  	"github.com/hyperledger/fabric/internal/peer/channel"
    17  	"github.com/hyperledger/fabric/internal/peer/common"
    18  	"github.com/hyperledger/fabric/internal/peer/lifecycle"
    19  	"github.com/hyperledger/fabric/internal/peer/node"
    20  	"github.com/hyperledger/fabric/internal/peer/version"
    21  	"github.com/spf13/cobra"
    22  	"github.com/spf13/viper"
    23  )
    24  
    25  // The main command describes the service and
    26  // defaults to printing the help message.
    27  var mainCmd = &cobra.Command{Use: "peer"}
    28  
    29  func main() {
    30  	// For environment variables.
    31  	viper.SetEnvPrefix(common.CmdRoot)
    32  	viper.AutomaticEnv()
    33  	replacer := strings.NewReplacer(".", "_")
    34  	viper.SetEnvKeyReplacer(replacer)
    35  
    36  	// Define command-line flags that are valid for all peer commands and
    37  	// subcommands.
    38  	mainFlags := mainCmd.PersistentFlags()
    39  
    40  	mainFlags.String("logging-level", "", "Legacy logging level flag")
    41  	viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
    42  	mainFlags.MarkHidden("logging-level")
    43  
    44  	cryptoProvider := factory.GetDefault()
    45  
    46  	mainCmd.AddCommand(version.Cmd())
    47  	mainCmd.AddCommand(node.Cmd())
    48  	mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider))
    49  	mainCmd.AddCommand(channel.Cmd(nil))
    50  	mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider))
    51  
    52  	// On failure Cobra prints the usage message and error string, so we only
    53  	// need to exit with a non-0 status
    54  	if mainCmd.Execute() != nil {
    55  		os.Exit(1)
    56  	}
    57  }