devcontainer

package
v1.202.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAtmosConfig

func SetAtmosConfig(config *schema.AtmosConfiguration)

SetAtmosConfig sets the Atmos configuration for the devcontainer command. SetAtmosConfig sets the package-level pointer to the provided AtmosConfiguration so devcontainer commands and providers can access the initialized configuration. It is intended to be called once during application initialization (for example, from root.go) after the Atmos configuration has been created.

Types

type AttachOptions

type AttachOptions struct {
	Instance string
	UsePTY   bool
}

AttachOptions contains parsed flags for the attach command.

type ConfigProvider

type ConfigProvider interface {
	// LoadAtmosConfig loads the Atmos configuration.
	LoadAtmosConfig() (*schema.AtmosConfiguration, error)

	// ListDevcontainers returns all configured devcontainer names, sorted.
	ListDevcontainers(config *schema.AtmosConfiguration) ([]string, error)

	// GetDevcontainerConfig retrieves configuration for a specific devcontainer.
	GetDevcontainerConfig(config *schema.AtmosConfiguration, name string) (*DevcontainerConfig, error)
}

ConfigProvider handles configuration loading and parsing.

type ContainerInfo

type ContainerInfo struct {
	Name     string
	Image    string
	Status   string
	Instance string
}

ContainerInfo contains information about a running container.

type DefaultConfigProvider

type DefaultConfigProvider struct{}

DefaultConfigProvider uses pkg/config for configuration.

func (*DefaultConfigProvider) GetDevcontainerConfig

func (d *DefaultConfigProvider) GetDevcontainerConfig(
	config *schema.AtmosConfiguration,
	name string,
) (*DevcontainerConfig, error)

GetDevcontainerConfig retrieves configuration for a specific devcontainer.

func (*DefaultConfigProvider) ListDevcontainers

func (d *DefaultConfigProvider) ListDevcontainers(config *schema.AtmosConfiguration) ([]string, error)

ListDevcontainers returns all configured devcontainer names, sorted.

func (*DefaultConfigProvider) LoadAtmosConfig

func (d *DefaultConfigProvider) LoadAtmosConfig() (*schema.AtmosConfiguration, error)

LoadAtmosConfig loads the Atmos configuration.

type DefaultUIProvider

type DefaultUIProvider struct{}

DefaultUIProvider uses terminal for UI operations.

func (*DefaultUIProvider) Confirm

func (d *DefaultUIProvider) Confirm(message string) (bool, error)

Confirm asks a yes/no question.

func (*DefaultUIProvider) Error

func (d *DefaultUIProvider) Error() io.Writer

Error returns the writer for error output.

func (*DefaultUIProvider) IsInteractive

func (d *DefaultUIProvider) IsInteractive() bool

IsInteractive returns true if running in an interactive terminal.

func (*DefaultUIProvider) Output

func (d *DefaultUIProvider) Output() io.Writer

Output returns the writer for normal output (typically stderr for UI).

func (*DefaultUIProvider) Prompt

func (d *DefaultUIProvider) Prompt(message string, options []string) (string, error)

Prompt displays a menu and returns the selected item.

type DevcontainerCommandProvider

type DevcontainerCommandProvider struct{}

DevcontainerCommandProvider implements the CommandProvider interface.

func (*DevcontainerCommandProvider) GetAliases

GetAliases returns command aliases (none for devcontainer).

func (*DevcontainerCommandProvider) GetCommand

func (d *DevcontainerCommandProvider) GetCommand() *cobra.Command

GetCommand returns the devcontainer command.

func (*DevcontainerCommandProvider) GetCompatibilityFlags

func (d *DevcontainerCommandProvider) GetCompatibilityFlags() map[string]compat.CompatibilityFlag

GetCompatibilityFlags returns compatibility flags for this command.

func (*DevcontainerCommandProvider) GetFlagsBuilder

func (d *DevcontainerCommandProvider) GetFlagsBuilder() flags.Builder

GetFlagsBuilder returns the flags builder for this command.

func (*DevcontainerCommandProvider) GetGroup

func (d *DevcontainerCommandProvider) GetGroup() string

GetGroup returns the command group for help organization.

func (*DevcontainerCommandProvider) GetName

func (d *DevcontainerCommandProvider) GetName() string

GetName returns the command name.

func (*DevcontainerCommandProvider) GetPositionalArgsBuilder

func (d *DevcontainerCommandProvider) GetPositionalArgsBuilder() *flags.PositionalArgsBuilder

GetPositionalArgsBuilder returns the positional args builder for this command.

type DevcontainerConfig

type DevcontainerConfig struct {
	Name      string
	Image     string
	BuildArgs map[string]string
	Mounts    []string
}

DevcontainerConfig represents parsed devcontainer configuration.

type DockerRuntimeProvider

type DockerRuntimeProvider struct {
	// contains filtered or unexported fields
}

DockerRuntimeProvider uses pkg/devcontainer for runtime operations.

func NewDockerRuntimeProvider

func NewDockerRuntimeProvider() *DockerRuntimeProvider

NewDockerRuntimeProvider creates a new Docker runtime provider.

func (*DockerRuntimeProvider) Attach

func (d *DockerRuntimeProvider) Attach(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts AttachOptions) error

Attach attaches to a running devcontainer.

func (*DockerRuntimeProvider) Exec

func (d *DockerRuntimeProvider) Exec(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, cmd []string, opts ExecOptions) error

Exec executes a command in a running devcontainer.

func (*DockerRuntimeProvider) ListRunning

func (d *DockerRuntimeProvider) ListRunning(ctx context.Context) ([]ContainerInfo, error)

ListRunning returns all running devcontainer instances.

func (*DockerRuntimeProvider) Logs

Logs retrieves logs from a devcontainer.

func (*DockerRuntimeProvider) Rebuild

func (d *DockerRuntimeProvider) Rebuild(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts RebuildOptions) error

Rebuild rebuilds a devcontainer.

func (*DockerRuntimeProvider) Remove

func (d *DockerRuntimeProvider) Remove(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts RemoveOptions) error

Remove removes a devcontainer.

func (*DockerRuntimeProvider) Start

func (d *DockerRuntimeProvider) Start(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts StartOptions) error

Start starts a devcontainer.

func (*DockerRuntimeProvider) Stop

func (d *DockerRuntimeProvider) Stop(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts StopOptions) error

Stop stops a running devcontainer.

type ExecOptions

type ExecOptions struct {
	Instance    string
	Interactive bool
	UsePTY      bool
}

ExecOptions contains parsed flags for the exec command.

type LogsOptions

type LogsOptions struct {
	Instance string
	Follow   bool
	Tail     string
}

LogsOptions contains parsed flags for the logs command.

type RebuildOptions

type RebuildOptions struct {
	Instance string
	Attach   bool
	NoPull   bool
	Identity string
}

RebuildOptions contains parsed flags for the rebuild command.

type RemoveOptions

type RemoveOptions struct {
	Instance string
	Force    bool
}

RemoveOptions contains parsed flags for the remove command.

type RuntimeProvider

type RuntimeProvider interface {
	// ListRunning returns all running devcontainer instances.
	ListRunning(ctx context.Context) ([]ContainerInfo, error)

	// Start starts a devcontainer.
	Start(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts StartOptions) error

	// Stop stops a running devcontainer.
	Stop(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts StopOptions) error

	// Attach attaches to a running devcontainer.
	Attach(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts AttachOptions) error

	// Exec executes a command in a running devcontainer.
	Exec(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, cmd []string, opts ExecOptions) error

	// Logs retrieves logs from a devcontainer.
	Logs(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts LogsOptions) (io.ReadCloser, error)

	// Remove removes a devcontainer.
	Remove(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts RemoveOptions) error

	// Rebuild rebuilds a devcontainer.
	Rebuild(ctx context.Context, atmosConfig *schema.AtmosConfiguration, name string, opts RebuildOptions) error
}

RuntimeProvider abstracts container runtime operations.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service coordinates devcontainer operations.

func NewService

func NewService() *Service

NewService creates a service with default providers.

func NewTestableService

func NewTestableService(
	config ConfigProvider,
	runtime RuntimeProvider,
	ui UIProvider,
) *Service

NewTestableService creates a Service configured with the provided config, runtime, and UI providers for use in tests.

func NewTestableServiceWithLogOutput

func NewTestableServiceWithLogOutput(
	config ConfigProvider,
	runtime RuntimeProvider,
	ui UIProvider,
	logOutput io.Writer,
) *Service

NewTestableServiceWithLogOutput creates a Service for tests with a custom log output writer.

func (*Service) Attach

func (s *Service) Attach(ctx context.Context, name string, opts AttachOptions) error

Attach attaches to a running devcontainer.

func (*Service) Exec

func (s *Service) Exec(ctx context.Context, name string, cmd []string, opts ExecOptions) error

Exec executes a command in a running devcontainer.

func (*Service) Initialize

func (s *Service) Initialize() error

Initialize loads the Atmos configuration. Call this once during startup.

func (*Service) InitializeWithConfig

func (s *Service) InitializeWithConfig(config *schema.AtmosConfiguration)

InitializeWithConfig sets the Atmos configuration directly. Use this in tests or when config is already available.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]ContainerInfo, error)

List lists all running devcontainers.

func (*Service) Logs

func (s *Service) Logs(ctx context.Context, name string, opts LogsOptions) error

Logs retrieves logs from a devcontainer and streams them to the configured output.

func (*Service) Rebuild

func (s *Service) Rebuild(ctx context.Context, name string, opts RebuildOptions) error

Rebuild rebuilds a devcontainer.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, name string, opts RemoveOptions) error

Remove removes a devcontainer.

func (*Service) ResolveDevcontainerName

func (s *Service) ResolveDevcontainerName(ctx context.Context, args []string) (string, error)

ResolveDevcontainerName gets devcontainer name from args or prompts user. This is a common operation used by multiple commands.

func (*Service) SetLogOutput

func (s *Service) SetLogOutput(w io.Writer)

SetLogOutput sets the writer for log output. This allows tests and alternative frontends to capture or redirect log output.

func (*Service) Start

func (s *Service) Start(ctx context.Context, name string, opts StartOptions) error

Start starts a devcontainer.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context, name string, opts StopOptions) error

Stop stops a running devcontainer.

type ShellOptions

type ShellOptions struct {
	Instance string
	Identity string
	UsePTY   bool
	New      bool
	Replace  bool
	Rm       bool
	NoPull   bool
}

ShellOptions contains parsed flags for the shell command.

type StartOptions

type StartOptions struct {
	Instance string
	Attach   bool
	Identity string
}

StartOptions contains parsed flags for the start command.

type StopOptions

type StopOptions struct {
	Instance string
	Timeout  int
	Rm       bool
}

StopOptions contains parsed flags for the stop command.

type UIProvider

type UIProvider interface {
	// IsInteractive returns true if running in an interactive terminal.
	IsInteractive() bool

	// Prompt displays a menu and returns the selected item.
	Prompt(message string, options []string) (string, error)

	// Confirm asks a yes/no question.
	Confirm(message string) (bool, error)

	// Output returns the writer for normal output (typically stderr for UI).
	Output() io.Writer

	// Error returns the writer for error output.
	Error() io.Writer
}

UIProvider handles user interaction.

Jump to

Keyboard shortcuts

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