github.com/kaituanwang/hyperledger@v2.0.1+incompatible/internal/peer/version/version.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package version
     8  
     9  import (
    10  	"fmt"
    11  	"runtime"
    12  
    13  	"github.com/hyperledger/fabric/common/metadata"
    14  	"github.com/spf13/cobra"
    15  )
    16  
    17  // Program name
    18  const ProgramName = "peer"
    19  
    20  // Cmd returns the Cobra Command for Version
    21  func Cmd() *cobra.Command {
    22  	return cobraCommand
    23  }
    24  
    25  var cobraCommand = &cobra.Command{
    26  	Use:   "version",
    27  	Short: "Print fabric peer version.",
    28  	Long:  `Print current version of the fabric peer server.`,
    29  	RunE: func(cmd *cobra.Command, args []string) error {
    30  		if len(args) != 0 {
    31  			return fmt.Errorf("trailing args detected")
    32  		}
    33  		// Parsing of the command line is done so silence cmd usage
    34  		cmd.SilenceUsage = true
    35  		fmt.Print(GetInfo())
    36  		return nil
    37  	},
    38  }
    39  
    40  // GetInfo returns version information for the peer
    41  func GetInfo() string {
    42  	ccinfo := fmt.Sprintf("  Base Docker Namespace: %s\n"+
    43  		"  Base Docker Label: %s\n"+
    44  		"  Docker Namespace: %s\n",
    45  		metadata.BaseDockerNamespace,
    46  		metadata.BaseDockerLabel,
    47  		metadata.DockerNamespace)
    48  
    49  	return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n"+
    50  		" OS/Arch: %s\n"+
    51  		" Chaincode:\n%s\n",
    52  		ProgramName, metadata.Version, metadata.CommitSHA, runtime.Version(),
    53  		fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), ccinfo)
    54  }