@@ -23,6 +23,7 @@ import (
23
23
"github.com/hyperledger/fabric/common/util"
24
24
"github.com/hyperledger/fabric/peer/common"
25
25
"github.com/spf13/cobra"
26
+ "github.com/spf13/pflag"
26
27
)
27
28
28
29
const (
@@ -33,47 +34,25 @@ const (
33
34
34
35
var logger = flogging .MustGetLogger ("chaincodeCmd" )
35
36
36
- func AddFlags (cmd * cobra.Command ) {
37
+ func addFlags (cmd * cobra.Command ) {
37
38
flags := cmd .PersistentFlags ()
38
39
39
- flags .StringVarP (& chaincodeLang , "lang" , "l" , "golang" ,
40
- fmt .Sprintf ("Language the %s is written in" , chainFuncName ))
41
- flags .StringVarP (& chaincodeCtorJSON , "ctor" , "c" , "{}" ,
42
- fmt .Sprintf ("Constructor message for the %s in JSON format" , chainFuncName ))
43
- flags .StringVarP (& chaincodePath , "path" , "p" , common .UndefinedParamValue ,
44
- fmt .Sprintf ("Path to %s" , chainFuncName ))
45
- flags .StringVarP (& chaincodeName , "name" , "n" , common .UndefinedParamValue ,
46
- fmt .Sprint ("Name of the chaincode" ))
47
- flags .StringVarP (& chaincodeVersion , "version" , "v" , common .UndefinedParamValue ,
48
- fmt .Sprint ("Version of the chaincode specified in install/instantiate/upgrade commands" ))
49
- flags .StringVarP (& chaincodeUsr , "username" , "u" , common .UndefinedParamValue ,
50
- fmt .Sprint ("Username for chaincode operations when security is enabled" ))
51
- flags .StringVarP (& customIDGenAlg , "tid" , "t" , common .UndefinedParamValue ,
52
- fmt .Sprint ("Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64" ))
53
- flags .StringVarP (& chainID , "chainID" , "C" , util .GetTestChainID (),
54
- fmt .Sprint ("The chain on which this command should be executed" ))
55
- flags .StringVarP (& policy , "policy" , "P" , common .UndefinedParamValue ,
56
- fmt .Sprint ("The endorsement policy associated to this chaincode" ))
57
- flags .StringVarP (& escc , "escc" , "E" , common .UndefinedParamValue ,
58
- fmt .Sprint ("The name of the endorsement system chaincode to be used for this chaincode" ))
59
- flags .StringVarP (& vscc , "vscc" , "V" , common .UndefinedParamValue ,
60
- fmt .Sprint ("The name of the verification system chaincode to be used for this chaincode" ))
61
40
flags .StringVarP (& orderingEndpoint , "orderer" , "o" , "" , "Ordering service endpoint" )
62
41
flags .BoolVarP (& tls , "tls" , "" , false , "Use TLS when communicating with the orderer endpoint" )
63
42
flags .StringVarP (& caFile , "cafile" , "" , "" , "Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint" )
64
43
}
65
44
66
45
// Cmd returns the cobra command for Chaincode
67
46
func Cmd (cf * ChaincodeCmdFactory ) * cobra.Command {
68
- AddFlags (chaincodeCmd )
47
+ addFlags (chaincodeCmd )
69
48
49
+ chaincodeCmd .AddCommand (installCmd (cf ))
70
50
chaincodeCmd .AddCommand (instantiateCmd (cf ))
71
51
chaincodeCmd .AddCommand (invokeCmd (cf ))
72
- chaincodeCmd .AddCommand (queryCmd (cf ))
73
- chaincodeCmd .AddCommand (upgradeCmd (cf ))
74
52
chaincodeCmd .AddCommand (packageCmd (cf , nil ))
75
- chaincodeCmd .AddCommand (installCmd (cf ))
53
+ chaincodeCmd .AddCommand (queryCmd (cf ))
76
54
chaincodeCmd .AddCommand (signpackageCmd (cf ))
55
+ chaincodeCmd .AddCommand (upgradeCmd (cf ))
77
56
78
57
return chaincodeCmd
79
58
}
84
63
chaincodeCtorJSON string
85
64
chaincodePath string
86
65
chaincodeName string
87
- chaincodeUsr string
66
+ chaincodeUsr string // Not used
88
67
chaincodeQueryRaw bool
89
68
chaincodeQueryHex bool
90
69
customIDGenAlg string
@@ -104,3 +83,48 @@ var chaincodeCmd = &cobra.Command{
104
83
Short : fmt .Sprint (shortDes ),
105
84
Long : fmt .Sprint (longDes ),
106
85
}
86
+
87
+ var flags * pflag.FlagSet
88
+
89
+ func init () {
90
+ resetFlags ()
91
+ }
92
+
93
+ // Explicitly define a method to facilitate tests
94
+ func resetFlags () {
95
+ flags = & pflag.FlagSet {}
96
+
97
+ flags .StringVarP (& chaincodeLang , "lang" , "l" , "golang" ,
98
+ fmt .Sprintf ("Language the %s is written in" , chainFuncName ))
99
+ flags .StringVarP (& chaincodeCtorJSON , "ctor" , "c" , "{}" ,
100
+ fmt .Sprintf ("Constructor message for the %s in JSON format" , chainFuncName ))
101
+ flags .StringVarP (& chaincodePath , "path" , "p" , common .UndefinedParamValue ,
102
+ fmt .Sprintf ("Path to %s" , chainFuncName ))
103
+ flags .StringVarP (& chaincodeName , "name" , "n" , common .UndefinedParamValue ,
104
+ fmt .Sprint ("Name of the chaincode" ))
105
+ flags .StringVarP (& chaincodeVersion , "version" , "v" , common .UndefinedParamValue ,
106
+ fmt .Sprint ("Version of the chaincode specified in install/instantiate/upgrade commands" ))
107
+ flags .StringVarP (& chaincodeUsr , "username" , "u" , common .UndefinedParamValue ,
108
+ fmt .Sprint ("Username for chaincode operations when security is enabled" ))
109
+ flags .StringVarP (& customIDGenAlg , "tid" , "t" , common .UndefinedParamValue ,
110
+ fmt .Sprint ("Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64" ))
111
+ flags .StringVarP (& chainID , "channelID" , "C" , util .GetTestChainID (),
112
+ fmt .Sprint ("The channel on which this command should be executed" ))
113
+ flags .StringVarP (& policy , "policy" , "P" , common .UndefinedParamValue ,
114
+ fmt .Sprint ("The endorsement policy associated to this chaincode" ))
115
+ flags .StringVarP (& escc , "escc" , "E" , common .UndefinedParamValue ,
116
+ fmt .Sprint ("The name of the endorsement system chaincode to be used for this chaincode" ))
117
+ flags .StringVarP (& vscc , "vscc" , "V" , common .UndefinedParamValue ,
118
+ fmt .Sprint ("The name of the verification system chaincode to be used for this chaincode" ))
119
+ }
120
+
121
+ func attachFlags (cmd * cobra.Command , names []string ) {
122
+ cmdFlags := cmd .Flags ()
123
+ for _ , name := range names {
124
+ if flag := flags .Lookup (name ); flag != nil {
125
+ cmdFlags .AddFlag (flag )
126
+ } else {
127
+ logger .Fatalf ("Could not find flag '%s' to attach to commond '%s'" , name , cmd .Name ())
128
+ }
129
+ }
130
+ }
0 commit comments