|
| 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-lib-go/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/snapshot" |
| 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: "cli"} |
| 28 | + |
| 29 | +func main() { |
| 30 | + setEnvConfig(viper.GetViper()) |
| 31 | + |
| 32 | + // Define command-line flags that are valid for all cli commands and |
| 33 | + // subcommands. |
| 34 | + mainFlags := mainCmd.PersistentFlags() |
| 35 | + |
| 36 | + mainFlags.String("logging-level", "", "Legacy logging level flag") |
| 37 | + viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level")) |
| 38 | + mainFlags.MarkHidden("logging-level") |
| 39 | + |
| 40 | + cryptoProvider := factory.GetDefault() |
| 41 | + |
| 42 | + mainCmd.AddCommand(version.Cmd()) |
| 43 | + mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider)) |
| 44 | + mainCmd.AddCommand(channel.Cmd(nil)) |
| 45 | + mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider)) |
| 46 | + mainCmd.AddCommand(snapshot.Cmd(cryptoProvider)) |
| 47 | + |
| 48 | + // On failure Cobra prints the usage message and error string, so we only |
| 49 | + // need to exit with a non-0 status |
| 50 | + if mainCmd.Execute() != nil { |
| 51 | + os.Exit(1) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +func setEnvConfig(v *viper.Viper) { |
| 56 | + v.SetEnvPrefix(common.CmdRoot) |
| 57 | + v.AllowEmptyEnv(true) |
| 58 | + v.AutomaticEnv() |
| 59 | + replacer := strings.NewReplacer(".", "_") |
| 60 | + v.SetEnvKeyReplacer(replacer) |
| 61 | +} |
0 commit comments