cli

package
v0.15.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DefaultSSHKeyPath is the fallback location for the SSH private key when provisioning remote machines.
	// Used when no key is explicitly provided and SSH agent authentication fails.
	DefaultSSHKeyPath  = "~/.ssh/id_ed25519"
	DefaultContextName = "default"
)

Variables

This section is empty.

Functions

func BindEnvToFlag added in v0.12.2

func BindEnvToFlag(cmd *cobra.Command, flagName, envVar string)

BindEnvToFlag assigns the value of an environment variable to the given command flag if the flag has not been set.

func Confirm

func Confirm() (bool, error)

func ConnectCluster added in v0.12.2

func ConnectCluster(ctx context.Context, conn config.MachineConnection, opts ConnectOptions) (*client.Client, error)

func ExpandCommaSeparatedValues added in v0.6.0

func ExpandCommaSeparatedValues(values []string) []string

ExpandCommaSeparatedValues takes a slice of strings and expands any comma-separated values into individual elements.

func IsStdinTerminal added in v0.12.2

func IsStdinTerminal() bool

IsStdinTerminal checks if the standard input is a terminal (TTY).

func IsStdoutTerminal added in v0.12.2

func IsStdoutTerminal() bool

IsStdoutTerminal checks if the standard output is a terminal (TTY).

func ServicesThatNeedBuild added in v0.14.0

func ServicesThatNeedBuild(
	project *composetypes.Project, selectedServices []string, deps bool,
) ([]composetypes.ServiceConfig, error)

ServicesThatNeedBuild returns a list of services that require building. deps indicates whether to include services that are dependencies of the selected services. Implementation is based on the logic from docker/compose/v2/pkg/compose/build.go.

Types

type AddMachineOptions added in v0.7.0

type AddMachineOptions struct {
	MachineName   string
	PublicIP      *netip.Addr
	RemoteMachine *RemoteMachine
	SkipInstall   bool
	Version       string
}

type BuildServicesOptions added in v0.14.0

type BuildServicesOptions struct {
	// BuildArgs sets build-time variables for services. Used in Dockerfiles that declare variables with ARG.
	BuildArgs []string
	// Check the build configuration for services without building them.
	Check bool
	// Deps enables to also build services declared as dependencies of the selected Services.
	Deps bool
	// NoCache disables the use of cache when building images.
	NoCache bool
	// Pull attempts to pull newer versions of the base images before building.
	Pull bool
	// Services specifies which services to build. If empty, all services with a build config are built.
	Services []string

	// Push targets are mutually exclusive.
	// PushCluster uploads the built images to cluster machines after building.
	PushCluster bool
	// PushRegistry uploads the built images to external registries after building.
	PushRegistry bool

	// Cluster-specific options (only used if PushCluster is true).
	// Machines is a list of machine names or IDs to push the image to. If empty, images are pushed to all machines.
	Machines []string
}

BuildServicesOptions contains options for building services in a Compose project.

type CLI

type CLI struct {
	Config *config.Config
	// contains filtered or unexported fields
}

func New

func New(configPath string, conn *config.MachineConnection, contextName string) (*CLI, error)

New creates a new CLI instance with the given config path or remote machine connection. If the connection is provided, the config is ignored for all operations which is useful for interacting with a cluster without creating a config. If a non-empty context name is given, it will override the current default.

func (*CLI) AddMachine

func (cli *CLI) AddMachine(ctx context.Context, opts AddMachineOptions) (*client.Client, *client.Client, error)

AddMachine provisions a remote machine and adds it to the cluster. It returns a cluster client and a machine client. The cluster client is connected to the existing machine in the cluster. It was used to add the new machine to the cluster. The machine client is connected to the new machine and can be used to interact with it. Both client should be closed after use by the caller.

func (*CLI) BuildServices added in v0.14.0

func (cli *CLI) BuildServices(ctx context.Context, project *composetypes.Project, opts BuildServicesOptions) error

BuildServices builds images for services in the Compose project.

func (*CLI) ConnectCluster

func (cli *CLI) ConnectCluster(ctx context.Context) (*client.Client, error)

ConnectCluster connects to a cluster using the context override or the current context if not specified. If the CLI was initialised with a machine connection, the config is ignored and the connection is used instead.

func (*CLI) ConnectClusterWithOptions added in v0.12.2

func (cli *CLI) ConnectClusterWithOptions(ctx context.Context, opts ConnectOptions) (*client.Client, error)

ConnectClusterWithOptions connects to a cluster with the given options. If the CLI was initialised with a machine connection, the config is ignored and the connection is used instead. If the CLI has an override context, it is used instead of the current default. Options are useful when using the CLI as a library where you may want to disable visual feedback.

func (*CLI) CreateContext added in v0.6.0

func (cli *CLI) CreateContext(name string) error

func (*CLI) GetContextOverrideOrCurrent added in v0.15.0

func (cli *CLI) GetContextOverrideOrCurrent() string

func (*CLI) InitCluster

func (cli *CLI) InitCluster(ctx context.Context, opts InitClusterOptions) (*client.Client, error)

InitCluster initialises a new cluster on a remote machine and returns a client to interact with the cluster. The client should be closed after use by the caller.

func (*CLI) ProgressOut

func (cli *CLI) ProgressOut() *streams.Out

ProgressOut returns an output stream for progress writer.

func (*CLI) SetCurrentContext added in v0.6.0

func (cli *CLI) SetCurrentContext(name string) error

type ConnectOptions added in v0.12.2

type ConnectOptions struct {
	// Whether to show connection progress spinner if stdout is a terminal or progress logs if not.
	ShowProgress bool
}

ConnectOptions configures the behavior of cluster connection attempts.

type InitClusterOptions added in v0.7.0

type InitClusterOptions struct {
	Context       string
	MachineName   string
	Network       netip.Prefix
	PublicIP      *netip.Addr
	RemoteMachine *RemoteMachine
	SkipInstall   bool
	Version       string
}

type RemoteMachine

type RemoteMachine struct {
	User      string
	Host      string
	Port      int
	KeyPath   string
	UseSSHCLI bool // indicates ssh+cli:// should be used
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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