command

package
v28.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 67 Imported by: 4,906

Documentation

Index

Constants

View Source
const (
	// DefaultContextName is the name reserved for the default context (config & env based)
	DefaultContextName = "default"

	// EnvOverrideContext is the name of the environment variable that can be
	// used to override the context to use. If set, it overrides the context
	// that's set in the CLI's configuration file, but takes no effect if the
	// "DOCKER_HOST" env-var is set (which takes precedence.
	EnvOverrideContext = "DOCKER_CONTEXT"
)

Variables

View Source
var ErrPromptTerminated = errdefs.Cancelled(errors.New("prompt terminated"))

Functions

func AddPlatformFlag

func AddPlatformFlag(flags *pflag.FlagSet, target *string)

AddPlatformFlag adds `platform` to a set of flags for API version 1.32 and later.

func AddTrustSigningFlags

func AddTrustSigningFlags(fs *pflag.FlagSet, v *bool, trusted bool)

AddTrustSigningFlags adds "signing" flags to the provided flagset

func AddTrustVerificationFlags

func AddTrustVerificationFlags(fs *pflag.FlagSet, v *bool, trusted bool)

AddTrustVerificationFlags adds content trust flags to the provided flagset

func BaseCommandAttributes

func BaseCommandAttributes(cmd *cobra.Command, streams Streams) []attribute.KeyValue

BaseCommandAttributes returns an attribute.Set containing attributes to attach to metrics/traces

func ConfigureAuth deprecated

func ConfigureAuth(ctx context.Context, cli Cli, flUser, flPassword string, authConfig *registrytypes.AuthConfig, _ bool) error

ConfigureAuth handles prompting of user's username and password if needed.

Deprecated: use PromptUserForCredentials instead.

func CopyToFile

func CopyToFile(outfile string, r io.Reader) error

CopyToFile writes the content of the reader to the specified file

func DefaultContextStoreConfig

func DefaultContextStoreConfig() store.Config

DefaultContextStoreConfig returns a new store.Config with the default set of endpoints configured.

func DisableInputEcho

func DisableInputEcho(ins *streams.In) (restore func() error, err error)

DisableInputEcho disables input echo on the provided streams.In. This is useful when the user provides sensitive information like passwords. The function returns a restore function that should be called to restore the terminal state.

func GetDefaultAuthConfig

func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error)

GetDefaultAuthConfig gets the default auth config given a serverAddress If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it

func NewAPIClientFromFlags

func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.ConfigFile) (client.APIClient, error)

NewAPIClientFromFlags creates a new APIClient from command line flags

func PrettyPrint

func PrettyPrint(i any) string

PrettyPrint outputs arbitrary data for human formatted output by uppercasing the first letter.

func PromptForConfirmation

func PromptForConfirmation(ctx context.Context, ins io.Reader, outs io.Writer, message string) (bool, error)

PromptForConfirmation requests and checks confirmation from the user. This will display the provided message followed by ' y/N '. If the user input 'y' or 'Y' it returns true otherwise false. If no message is provided, "Are you sure you want to proceed? y/N " will be used instead.

If the user terminates the CLI with SIGINT or SIGTERM while the prompt is active, the prompt will return false with an ErrPromptTerminated error. When the prompt returns an error, the caller should propagate the error up the stack and close the io.Reader used for the prompt which will prevent the background goroutine from blocking indefinitely.

func PromptForInput

func PromptForInput(ctx context.Context, in io.Reader, out io.Writer, message string) (string, error)

PromptForInput requests input from the user.

If the user terminates the CLI with SIGINT or SIGTERM while the prompt is active, the prompt will return an empty string ("") with an ErrPromptTerminated error. When the prompt returns an error, the caller should propagate the error up the stack and close the io.Reader used for the prompt which will prevent the background goroutine from blocking indefinitely.

func PromptUserForCredentials

func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword, defaultUsername, serverAddress string) (registrytypes.AuthConfig, error)

PromptUserForCredentials handles the CLI prompt for the user to input credentials. If argUser is not empty, then the user is only prompted for their password. If argPassword is not empty, then the user is only prompted for their username If neither argUser nor argPassword are empty, then the user is not prompted and an AuthConfig is returned with those values. If defaultUsername is not empty, the username prompt includes that username and the user can hit enter without inputting a username to use that default username.

func PruneFilters

func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args

PruneFilters returns consolidated prune filters obtained from config.json and cli

func