container

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT-0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ShellUnknown = ""     // not yet tested
	ShellNone    = "none" // no shell found
)

Shell detection results.

View Source
const KeySep = "::"

KeySep is the separator between host alias and container name in composite keys. Using "::" because "--" can appear in SSH host aliases.

Variables

View Source
var ShellCandidates = []string{"bash", "sh", "ash"}

ShellCandidates lists shell names to search via "command -v" during detection.

Functions

func AddIncludeLine

func AddIncludeLine(sshConfigPath, includePath string) error

AddIncludeLine adds an `Include` directive to ~/.ssh/config if not already present. Uses raw text manipulation to avoid stripping comments.

func DefaultCachePath

func DefaultCachePath() (string, error)

DefaultCachePath returns the default cache file path.

func DefaultIncludePath

func DefaultIncludePath() (string, error)

DefaultIncludePath returns the default path for the generated SSH config include file.

func GenerateIncludeFile

func GenerateIncludeFile(cache *Cache, outputPath string) error

GenerateIncludeFile creates the SSH config include file at the given path with Host entries for all cached containers. Uses ProxyJump to route through the parent host, so all parent SSH config (keys, proxies, etc.) is inherited.

func ValidateName

func ValidateName(name string) bool

ValidateName checks if a container name is safe to use in SSH config and shell commands. Also used for user-provided aliases.

Types

type Cache

type Cache struct {
	Hosts map[string]HostCache `json:"hosts"`
	// contains filtered or unexported fields
}

Cache stores discovered container data locally.

func LoadCache

func LoadCache(path string) (*Cache, error)

LoadCache loads the container cache from disk. Returns an empty cache if the file doesn't exist or is corrupted.

func (*Cache) AllContainers

func (c *Cache) AllContainers() []Container

AllContainers returns all cached containers across all hosts.

func (*Cache) CacheAge

func (c *Cache) CacheAge(hostAlias string) string

CacheAge returns a human-readable age string for a host's cache.

func (*Cache) GetContainers

func (c *Cache) GetContainers(hostAlias string) []Container

GetContainers returns cached containers for a host.

func (*Cache) IsStale

func (c *Cache) IsStale(hostAlias string, maxAge time.Duration) bool

IsStale returns true if the cache for the given host is older than maxAge, or if the host is not in the cache.

func (*Cache) MergeUpdate

func (c *Cache) MergeUpdate(hostAlias string, discovered []Container)

MergeUpdate merges newly discovered containers with existing cached data. Keeps aliases for containers that are still running, adds new containers, and marks stopped containers with empty status.

func (*Cache) RefreshExisting added in v1.1.2

func (c *Cache) RefreshExisting(hostAlias string, discovered []Container)

RefreshExisting updates only containers already in cache for a host. Preserves aliases and shell info. Removes containers that are no longer running. Does NOT add newly discovered containers that weren't previously selected.

func (*Cache) RemoveStaleHosts

func (c *Cache) RemoveStaleHosts(validHosts []string)

RemoveStaleHosts removes cached entries for hosts not in the provided list.

func (*Cache) RenameHost

func (c *Cache) RenameHost(oldAlias, newAlias string)

RenameHost moves all cached containers from oldAlias to newAlias.

func (*Cache) Save

func (c *Cache) Save() error

Save writes the cache to disk atomically.

func (*Cache) Update

func (c *Cache) Update(hostAlias string, containers []Container)

Update replaces the cached containers for a host.

type Container

type Container struct {
	ID     string `json:"id"`
	Name   string `json:"name"`            // original Docker container name
	Alias  string `json:"alias,omitempty"` // user-defined display name (defaults to Name)
	Image  string `json:"image"`
	Status string `json:"status"`
	Host   string `json:"host"`            // parent SSH host alias
	Shell  string `json:"shell,omitempty"` // detected shell path, empty = unknown, "none" = no shell
}

Container represents a Docker container discovered on a remote host.

func Discover

func Discover(hostAlias string, timeout time.Duration, verbose bool) ([]Container, error)

Discover runs `docker ps` on a remote host via SSH and returns the list of running containers.

func (Container) DisplayName

func (c Container) DisplayName() string

DisplayName returns the alias if set, otherwise the original name.

func (Container) Key

func (c Container) Key() string

Key returns the composite key for this container: "host::name".

func (Container) ShellLabel

func (c Container) ShellLabel() string

ShellLabel returns a short label for display in the finder.

type DiscoverResult

type DiscoverResult struct {
	Host       string
	Containers []Container
	Err        error
}

DiscoverResult holds the result of discovering containers on a single host.

func DiscoverAll

func DiscoverAll(hosts []string, timeout time.Duration, concurrency int, verbose bool) []DiscoverResult

DiscoverAll runs discovery on multiple hosts concurrently with a concurrency limit.

type HostCache

type HostCache struct {
	Containers []Container `json:"containers"`
	UpdatedAt  time.Time   `json:"updated_at"`
}

HostCache holds cached containers for a single host.

Jump to

Keyboard shortcuts

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