Skip to content

Commit 6f876ad

Browse files
author
Nao Nishijima
committed
[FAB-4350] Add version cmd to configtxgen
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 <[email protected]>
1 parent 7de874d commit 6f876ad

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

common/configtx/tool/configtxgen/main.go

+15
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import (
2222
"flag"
2323
"fmt"
2424
"io/ioutil"
25+
"os"
2526

2627
"github.com/hyperledger/fabric/bccsp/factory"
2728
"github.com/hyperledger/fabric/common/config"
2829
mspconfig "github.com/hyperledger/fabric/common/config/msp"
2930
"github.com/hyperledger/fabric/common/configtx"
31+
"github.com/hyperledger/fabric/common/configtx/tool/configtxgen/metadata"
3032
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
3133
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
3234
"github.com/hyperledger/fabric/common/flogging"
@@ -39,6 +41,8 @@ import (
3941
logging "github.com/op/go-logging"
4042
)
4143

44+
var exitCode = 0
45+
4246
var logger = flogging.MustGetLogger("common/configtx/tool")
4347

4448
func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock string) error {
@@ -337,6 +341,8 @@ func main() {
337341
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)")
338342
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")
339343

344+
version := flag.Bool("version", false, "Show version information")
345+
340346
flag.Parse()
341347

342348
logging.SetLevel(logging.INFO, "")
@@ -345,6 +351,11 @@ func main() {
345351
factory.InitFactories(nil)
346352
config := genesisconfig.Load(profile)
347353

354+
if *version {
355+
printVersion()
356+
os.Exit(exitCode)
357+
}
358+
348359
if outputBlock != "" {
349360
if err := doOutputBlock(config, channelID, outputBlock); err != nil {
350361
logger.Fatalf("Error on outputBlock: %s", err)
@@ -375,3 +386,7 @@ func main() {
375386
}
376387
}
377388
}
389+
390+
func printVersion() {
391+
fmt.Println(metadata.GetVersionInfo())
392+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2017 Hitachi America
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package metadata
18+
19+
import (
20+
"fmt"
21+
"runtime"
22+
)
23+
24+
// Package version
25+
var Version string
26+
27+
// Program name
28+
const ProgramName = "configtxgen"
29+
30+
func GetVersionInfo() string {
31+
if Version == "" {
32+
Version = "development build"
33+
}
34+
35+
return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
36+
ProgramName, Version, runtime.Version(),
37+
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2017 Hitachi America
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package metadata_test
18+
19+
import (
20+
"fmt"
21+
"runtime"
22+
"testing"
23+
24+
"github.com/hyperledger/fabric/common/configtx/tool/configtxgen/metadata"
25+
"github.com/stretchr/testify/assert"
26+
)
27+
28+
func TestGetVersionInfo(t *testing.T) {
29+
testVersion := "TestVersion"
30+
metadata.Version = testVersion
31+
32+
expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
33+
metadata.ProgramName, testVersion, runtime.Version(),
34+
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
35+
assert.Equal(t, expected, metadata.GetVersionInfo())
36+
}

0 commit comments

Comments
 (0)