File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,14 @@ var cobraCommand = &cobra.Command{
26
26
Use : "version" ,
27
27
Short : "Print fabric peer version." ,
28
28
Long : `Print current version of the fabric peer server.` ,
29
- Run : func (cmd * cobra.Command , args []string ) {
29
+ RunE : func (cmd * cobra.Command , args []string ) error {
30
+ if len (args ) != 0 {
31
+ return fmt .Errorf ("trailing args detected" )
32
+ }
33
+ // Parsing of the command line is done so silence cmd usage
34
+ cmd .SilenceUsage = true
30
35
fmt .Print (GetInfo ())
36
+ return nil
31
37
},
32
38
}
33
39
Original file line number Diff line number Diff line change @@ -26,3 +26,10 @@ func TestCmd(t *testing.T) {
26
26
cmd := Cmd ()
27
27
assert .NoError (t , cmd .Execute (), "expected version command to succeed" )
28
28
}
29
+
30
+ func TestCmdWithTrailingArgs (t * testing.T ) {
31
+ cmd := Cmd ()
32
+ args := []string {"trailingargs" }
33
+ cmd .SetArgs (args )
34
+ assert .EqualError (t , cmd .Execute (), "trailing args detected" )
35
+ }
You can’t perform that action at this time.
0 commit comments