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.
@@ -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
+ }
+}
