cli/command: add WithAPIClient

This allows the cli to be initialized with a (custom) API client.
Currently to be used for unit tests, but could be used for other
scenarios.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-12-05 21:35:05 +01:00
parent 74874cd0c9
commit 21e45ff852
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 9 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"strconv"
"github.com/docker/cli/cli/streams"
"github.com/docker/docker/client"
"github.com/moby/term"
)
@ -86,3 +87,11 @@ func WithDefaultContextStoreConfig() DockerCliOption {
return nil
}
}
// WithAPIClient configures the cli to use the given API client.
func WithAPIClient(c client.APIClient) DockerCliOption {
return func(cli *DockerCli) error {
cli.client = c
return nil
}
}