File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -345,7 +345,7 @@ func GetClientQueryContext(cmd *cobra.Command) (Context, error) {
345
345
// - client.Context field pre-populated & flag not set: uses pre-populated value
346
346
// - client.Context field pre-populated & flag set: uses set flag value
347
347
func GetClientTxContext (cmd * cobra.Command ) (Context , error ) {
348
- ctx := GetClientContextFromCmd (cmd )
348
+ ctx := GetClientContextFromCmd (cmd ). WithOutput ( cmd . OutOrStdout ())
349
349
return readTxCommandFlags (ctx , cmd .Flags ())
350
350
}
351
351
Original file line number Diff line number Diff line change 1
1
package client_test
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"fmt"
6
7
"testing"
@@ -137,3 +138,28 @@ func TestSetCmdClientContextHandler(t *testing.T) {
137
138
})
138
139
}
139
140
}
141
+
142
+ func TestContext_usesCobraCommandOutput (t * testing.T ) {
143
+ var initCtx client.Context
144
+
145
+ cmd := & cobra.Command {
146
+ PreRunE : func (cmd * cobra.Command , args []string ) error {
147
+ return client .SetCmdClientContextHandler (initCtx , cmd )
148
+ },
149
+ RunE : func (cmd * cobra.Command , _ []string ) error {
150
+ cctx , err := client .GetClientTxContext (cmd )
151
+ if err != nil {
152
+ return err
153
+ }
154
+
155
+ return cctx .PrintString ("hello" )
156
+ },
157
+ }
158
+
159
+ var outBuf bytes.Buffer
160
+ cmd .SetOutput (& outBuf )
161
+
162
+ require .NoError (t , cmd .Execute ())
163
+
164
+ require .Equal (t , "hello" , outBuf .String ())
165
+ }
You can’t perform that action at this time.
0 commit comments