config

package
v0.4.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ProjectFileName = "devrun.yaml"

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() string

ConfigDir returns ~/.config/devrun (or $XDG_CONFIG_HOME/devrun).

func DaemonPIDPath

func DaemonPIDPath() string

func DataDir

func DataDir() string

DataDir returns ~/.local/share/devrun (or $XDG_DATA_HOME/devrun).

func LogPath

func LogPath(name string) string

func ReAdoptServices

func ReAdoptServices(services map[string]*ServiceState)

ReAdoptServices checks each service's PID to determine if it is still alive. Alive → StatusRunning + ReAdopted=true. Dead → StatusCrashed, PID cleared. Modifies the map in place. Only checks services that have a non-nil PID.

func RegistryPath

func RegistryPath() string

func RemoveService

func RemoveService(src Source, name string) error

RemoveService deletes a service from whichever config src points at: the project devrun.yaml when src.IsLocal(), otherwise the global registry.

It errors when the named service is not defined in that config. Notifying a running daemon (so it evicts the service from its in-memory map) is the caller's responsibility.

func Resolve

func Resolve(dir string, global bool) (*Registry, Source, error)

Resolve determines which service registry is active for a command run in dir.

When global is false and dir contains a devrun.yaml, that file is loaded and converted to an in-memory Registry, and the returned Source points at it. Otherwise the global registry (~/.config/devrun/services.yaml) is returned with an empty Source. Project services are never written to the global registry, so it contains only services registered with `devrun add`.

func SaveProject

func SaveProject(dir string, p *ProjectConfig) error

SaveProject writes p to devrun.yaml in dir. The file is re-marshalled from the in-memory structure, so hand-written comments and key ordering are not preserved.

func SaveRegistry

func SaveRegistry(path string, reg *Registry) error

SaveRegistry writes the registry to path, creating parent directories as needed.

func SaveServiceEdit

func SaveServiceEdit(src Source, oldName, newName, command, cwd string) error

SaveServiceEdit changes an existing service's name, command, and working directory, then persists the result to whichever config src points at: the project devrun.yaml when src.IsLocal(), otherwise the global registry.

oldName identifies the service to edit. newName and command must be non-empty (after trimming); newName may equal oldName but must not collide with a different existing service. For a project file cwd is stored relative to src.Dir (and dropped when it is the project root); for the global registry it is stored as given. All other fields (group, env, desc) are preserved.

func SaveState

func SaveState(path string, s *State) error

SaveState writes state atomically: write to .tmp, then rename.

func SaveTargetEdit

func SaveTargetEdit(src Source, oldName, newName string, members []string) error

SaveTargetEdit renames a target and/or replaces its member list, persisting to whichever config src points at: the project devrun.yaml when src.IsLocal(), otherwise the global registry.

oldName identifies the target to edit. newName must be non-empty (after trimming); it may equal oldName but must not collide with a different target. members is stored sorted and de-duplicated; an empty list is allowed.

func SocketPath

func SocketPath() string

func SortedTargetNames

func SortedTargetNames(targets map[string][]string) []string

SortedTargetNames returns the target names in targets, sorted alphabetically.

func StatePath

func StatePath() string

Types

type ProjectConfig

type ProjectConfig struct {
	Name     string                           `yaml:"name,omitempty"`
	Services map[string]*ProjectServiceConfig `yaml:"services"`
	// Targets maps a target name to the service names it groups. See
	// Registry.Targets — the semantics are identical for a project file.
	Targets map[string][]string `yaml:"targets,omitempty"`
}

ProjectConfig is the top-level structure of devrun.yaml.

func LoadProject

func LoadProject(dir string) (*ProjectConfig, error)

LoadProject reads devrun.yaml from dir. Returns nil, nil if the file does not exist. If Name is empty it defaults to the sanitised base name of dir.

func (*ProjectConfig) ToServiceConfigs

func (p *ProjectConfig) ToServiceConfigs(dir string) map[string]*ServiceConfig

ToServiceConfigs converts a ProjectConfig to ServiceConfig entries ready for the global registry. Relative CWD values are resolved against dir.

type ProjectServiceConfig

type ProjectServiceConfig struct {
	Command string            `yaml:"command"`
	CWD     string            `yaml:"cwd,omitempty"`
	Env     map[string]string `yaml:"env,omitempty"`
	Desc    string            `yaml:"desc,omitempty"`
}

ProjectServiceConfig is a service entry in a devrun.yaml file.

func (*ProjectServiceConfig) Validate

func (c *ProjectServiceConfig) Validate() error

Validate mirrors ServiceConfig.Validate for a devrun.yaml service entry.

type Registry

type Registry struct {
	Version  string                    `yaml:"version"`
	Services map[string]*ServiceConfig `yaml:"services"`
	// Targets maps a target name to the service names it groups. A target is a
	// named subset of services that can be started or stopped as a unit. Members
	// that do not resolve to a known service are ignored at use time rather than
	// rejected on load, so removing a service never breaks config parsing.
	Targets map[string][]string `yaml:"targets,omitempty"`
}

Registry is the top-level structure of services.yaml.

func LoadRegistry

func LoadRegistry(path string) (*Registry, error)

LoadRegistry reads services.yaml. Returns an empty registry if the file does not exist.

func (*Registry) TargetMemberConfigs

func (r *Registry) TargetMemberConfigs(name string) []*ServiceConfig

TargetMemberConfigs resolves the members of target name to their service definitions, in the order listed. Members that are not a known service in the registry are skipped, and a name listed more than once is only returned once. An unknown target name yields nil.

type ServiceConfig

type ServiceConfig struct {
	Name    string            `yaml:"name" json:"name"`
	Command string            `yaml:"command" json:"command"`
	CWD     string            `yaml:"cwd,omitempty" json:"cwd,omitempty"`
	Group   string            `yaml:"group,omitempty" json:"group,omitempty"`
	Env     map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
	Desc    string            `yaml:"desc,omitempty" json:"desc,omitempty"`
}

ServiceConfig is the shared vocabulary across CLI, daemon, and config layer. YAML tags match the devrun.yaml and services.yaml schema. JSON tags are load bearing too: ServiceConfig crosses the wire as JSON in ipc.StartPayload and in the daemon re-exec handoff, so the field names must be pinned explicitly rather than left to default to the Go identifiers.

func (*ServiceConfig) Validate

func (c *ServiceConfig) Validate() error

Validate reports whether a service definition is runnable. The dominant failure is a blank command: the daemon would otherwise hand `sh -c` an empty script, which exits 0 immediately and is reported as a clean one-shot run.

type ServiceState

type ServiceState struct {
	Status       ServiceStatus `json:"state"`
	PID          *int          `json:"pid"`
	Port         *int          `json:"port"`
	StartedAt    *time.Time    `json:"started_at"`
	LastExitCode *int          `json:"last_exit_code"`
	ReAdopted    bool          `json:"re_adopted"`
}

type ServiceStatus

type ServiceStatus string
const (
	StatusStopped  ServiceStatus = "stopped"
	StatusStarting ServiceStatus = "starting"
	StatusRunning  ServiceStatus = "running"
	StatusCrashed  ServiceStatus = "crashed"
	StatusStopping ServiceStatus = "stopping"
	// StatusExited marks a process that terminated on its own with exit code 0
	// (e.g. a one-shot command), as opposed to StatusCrashed (non-zero exit or
	// killed by signal) or StatusStopped (terminated by `devrun stop`).
	StatusExited ServiceStatus = "exited"
)

func (ServiceStatus) IsLive

func (s ServiceStatus) IsLive() bool

IsLive reports whether the process is (or should be) running — i.e. uptime, CPU, and memory are meaningful. Terminal states (stopped, exited, crashed) are not live.

type Source

type Source struct {
	// Local is the path to the project devrun.yaml when one is active, or "" when
	// the global registry is in use.
	Local string
	// Dir is the directory the project devrun.yaml lives in. Empty for the global
	// registry.
	Dir string
}

Source describes where the active service registry for a command came from.

func (Source) IsLocal

func (s Source) IsLocal() bool

IsLocal reports whether a project devrun.yaml is the active config.

type State

type State struct {
	Version  int                      `json:"version"`
	Services map[string]*ServiceState `json:"services"`
	// ActiveTargets maps a currently-started target to the member service names
	// captured when it was started. `devrun target stop` consults this snapshot —
	// not the live config — so editing a target's membership while it runs does
	// not change what a later stop releases. A service is left running on stop if
	// it still appears under another active target.
	ActiveTargets map[string][]string `json:"active_targets,omitempty"`
}

func LoadState

func LoadState(path string) (*State, error)

LoadState reads state.json. Returns an empty state if the file does not exist.

Jump to

Keyboard shortcuts

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