Skip to content

Commit

Permalink
docs: add documentation for Exec method (#2451)
Browse files Browse the repository at this point in the history
Adds documentation for the Exec method in the DockerContainer struct.
  • Loading branch information
gustavosbarreto committed Apr 25, 2024
1 parent 5c0381c commit 441d5b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docker.go
Expand Up @@ -483,6 +483,13 @@ func (c *DockerContainer) NetworkAliases(ctx context.Context) (map[string][]stri
return a, nil
}

// Exec executes a command in the current container.
// It returns the exit status of the executed command, an [io.Reader] containing the combined
// stdout and stderr, and any encountered error. Note that reading directly from the [io.Reader]
// may result in unexpected bytes due to custom stream multiplexing headers.
// Use [tcexec.Multiplexed] option to read the combined output without the multiplexing headers.
// Alternatively, to separate the stdout and stderr from [io.Reader] and interpret these headers properly,
// [github.com/docker/docker/pkg/stdcopy.StdCopy] from the Docker API should be used.
func (c *DockerContainer) Exec(ctx context.Context, cmd []string, options ...tcexec.ProcessOption) (int, io.Reader, error) {
cli := c.provider.client

Expand Down
2 changes: 2 additions & 0 deletions exec/processor.go
Expand Up @@ -60,6 +60,8 @@ func WithEnv(env []string) ProcessOption {
})
}

// Multiplexed returns a [ProcessOption] that configures the command execution
// to combine stdout and stderr into a single stream without Docker's multiplexing headers.
func Multiplexed() ProcessOption {
return ProcessOptionFunc(func(opts *ProcessOptions) {
// returning fast to bypass those options with a nil reader,
Expand Down

0 comments on commit 441d5b2

Please sign in to comment.