Skip to content

Commit

Permalink
[FAB-4350] Add version cmd to configtxgen
Browse files Browse the repository at this point in the history
Adds a version cmd to configtxgen.
Version info is added to the binary using both
- make configtxgen
- make release[-all]

Change-Id: Ifc881edc7dc4f0802d67403fb06eaec732ef355a
Signed-off-by: Nao Nishijima <nao.nishijima@hal.hitachi.com>
  • Loading branch information
Nao Nishijima committed Jun 7, 2017
1 parent 7de874d commit 6f876ad
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
15 changes: 15 additions & 0 deletions common/configtx/tool/configtxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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, "")
Expand All @@ -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)
Expand Down Expand Up @@ -375,3 +386,7 @@ func main() {
}
}
}

func printVersion() {
fmt.Println(metadata.GetVersionInfo())
}
38 changes: 38 additions & 0 deletions common/configtx/tool/configtxgen/metadata/metadata.go
Original file line number Diff line number Diff line change
@@ -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))
}
36 changes: 36 additions & 0 deletions common/configtx/tool/configtxgen/metadata/metadata_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 6f876ad

Please sign in to comment.