From 21e45ff8524c08052226b9d1bd19cbab35bbaf64 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 5 Dec 2022 21:35:05 +0100 Subject: [PATCH] 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 --- cli/command/cli_options.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/command/cli_options.go b/cli/command/cli_options.go index 535a6d5338..d714947cb9 100644 --- a/cli/command/cli_options.go +++ b/cli/command/cli_options.go @@ -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 + } +}