docker

package
v5.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package docker provides Docker client lifecycle management for CLI commands.

This package contains utilities for creating and managing Docker client connections with automatic cleanup, suitable for use in Cobra command handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithClient

func WithClient(cmd *cobra.Command, operation func(client.APIClient) error) error

WithClient creates a Docker client, executes the given operation function, and ensures cleanup. The Docker client is automatically closed after the operation completes, regardless of success or failure.

This function is suitable for production use. For testing with mock clients, use WithClientInstance instead.

Returns an error if client creation fails or if the operation function returns an error.

func WithClientInstance

func WithClientInstance(
	cmd *cobra.Command,
	dockerClient client.APIClient,
	operation func(client.APIClient) error,
) error

WithClientInstance executes an operation with a provided Docker client and handles cleanup. The client will be closed after the operation completes, even if the operation returns an error.

This function is particularly useful for testing with mock clients, as it allows you to provide a pre-configured client instance. Any error during client cleanup is logged but does not cause the function to return an error if the operation itself succeeded.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL