diff --git a/common/configtx/tool/configtxgen/main.go b/common/configtx/tool/configtxgen/main.go index a1f329e114..31b9d69c1d 100644 --- a/common/configtx/tool/configtxgen/main.go +++ b/common/configtx/tool/configtxgen/main.go @@ -22,11 +22,13 @@ import ( "flag" "fmt" "io/ioutil" + "os" "github.com/hyperledger/fabric/bccsp/factory" "github.com/hyperledger/fabric/common/config" mspconfig "github.com/hyperledger/fabric/common/config/msp" "github.com/hyperledger/fabric/common/configtx" + "github.com/hyperledger/fabric/common/configtx/tool/configtxgen/metadata" genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" "github.com/hyperledger/fabric/common/configtx/tool/provisional" "github.com/hyperledger/fabric/common/flogging" @@ -39,6 +41,8 @@ import ( logging "github.com/op/go-logging" ) +var exitCode = 0 + var logger = flogging.MustGetLogger("common/configtx/tool") func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock string) error { @@ -337,6 +341,8 @@ func main() { flag.StringVar(&outputAnchorPeersUpdate, "outputAnchorPeersUpdate", "", "Creates an config update to update an anchor peer (works only with the default channel creation, and only for the first update)") flag.StringVar(&asOrg, "asOrg", "", "Performs the config generation as a particular organization, only including values in the write set that org (likely) has privilege to set") + version := flag.Bool("version", false, "Show version information") + flag.Parse() logging.SetLevel(logging.INFO, "") @@ -345,6 +351,11 @@ func main() { factory.InitFactories(nil) config := genesisconfig.Load(profile) + if *version { + printVersion() + os.Exit(exitCode) + } + if outputBlock != "" { if err := doOutputBlock(config, channelID, outputBlock); err != nil { logger.Fatalf("Error on outputBlock: %s", err) @@ -375,3 +386,7 @@ func main() { } } } + +func printVersion() { + fmt.Println(metadata.GetVersionInfo()) +} diff --git a/common/configtx/tool/configtxgen/metadata/metadata.go b/common/configtx/tool/configtxgen/metadata/metadata.go new file mode 100644 index 0000000000..7d42c09389 --- /dev/null +++ b/common/configtx/tool/configtxgen/metadata/metadata.go @@ -0,0 +1,38 @@ +/* +Copyright 2017 Hitachi America + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package metadata + +import ( + "fmt" + "runtime" +) + +// Package version +var Version string + +// Program name +const ProgramName = "configtxgen" + +func GetVersionInfo() string { + if Version == "" { + Version = "development build" + } + + return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s", + ProgramName, Version, runtime.Version(), + fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)) +} diff --git a/common/configtx/tool/configtxgen/metadata/metadata_test.go b/common/configtx/tool/configtxgen/metadata/metadata_test.go new file mode 100644 index 0000000000..bea76bdd6c --- /dev/null +++ b/common/configtx/tool/configtxgen/metadata/metadata_test.go @@ -0,0 +1,36 @@ +/* +Copyright 2017 Hitachi America + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package metadata_test + +import ( + "fmt" + "runtime" + "testing" + + "github.com/hyperledger/fabric/common/configtx/tool/configtxgen/metadata" + "github.com/stretchr/testify/assert" +) + +func TestGetVersionInfo(t *testing.T) { + testVersion := "TestVersion" + metadata.Version = testVersion + + expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s", + metadata.ProgramName, testVersion, runtime.Version(), + fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)) + assert.Equal(t, expected, metadata.GetVersionInfo()) +}