github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/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 Run: func(cmd *cobra.Command, args []string) { 30 fmt.Print(GetInfo()) 31 }, 32 } 33 34 // GetInfo returns version information for the peer 35 func GetInfo() string { 36 if metadata.Version == "" { 37 metadata.Version = "development build" 38 } 39 40 ccinfo := fmt.Sprintf(" Base Image Version: %s\n"+ 41 " Base Docker Namespace: %s\n"+ 42 " Base Docker Label: %s\n"+ 43 " Docker Namespace: %s\n", 44 metadata.BaseVersion, metadata.BaseDockerNamespace, 45 metadata.BaseDockerLabel, metadata.DockerNamespace) 46 47 return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s\n"+ 48 " Chaincode:\n %s\n", 49 ProgramName, metadata.Version, runtime.Version(), 50 fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), ccinfo) 51 }