github.com/true-sqn/fabric@v2.1.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 Label: %s\n"+
    43  		"  Docker Namespace: %s\n",
    44  		metadata.BaseDockerLabel,
    45  		metadata.DockerNamespace)
    46  
    47  	return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n"+
    48  		" OS/Arch: %s\n"+
    49  		" Chaincode:\n%s\n",
    50  		ProgramName, metadata.Version, metadata.CommitSHA, runtime.Version(),
    51  		fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), ccinfo)
    52  }