MCPcopy
hub / github.com/googleapis/mcp-toolbox / invokeCommandWithContext

Function invokeCommandWithContext

cmd/root_test.go:97–110  ·  view source on GitHub ↗

invokeCommandWithContext executes the command with a context and returns the captured output.

(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

95
96// invokeCommandWithContext executes the command with a context and returns the captured output.
97func invokeCommandWithContext(ctx context.Context, args []string) (*cobra.Command, *internal.ToolboxOptions, string, error) {
98 buf := new(bytes.Buffer)
99 opts := internal.NewToolboxOptions(internal.WithIOStreams(buf, buf))
100 c := NewCommand(opts)
101
102 // Capture output using a buffer
103 c.SetArgs(args)
104 c.SilenceUsage = true
105 c.SilenceErrors = true
106 c.SetContext(ctx)
107
108 err := c.Execute()
109 return c, opts, buf.String(), err
110}
111
112func TestVersion(t *testing.T) {
113 data, err := os.ReadFile("version.txt")

Callers 3

Calls 4

NewToolboxOptionsFunction · 0.92
WithIOStreamsFunction · 0.92
NewCommandFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected