lib

package
v0.2.2-beta Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

The lib package is the implementation of the core functionality of the raid CLI tool.

Index

Constants

View Source
const (
	ConfigDirName       = ".raid"
	ConfigFileName      = "config.toml"
	ConfigPathDefault   = "~" + sys.Sep + ConfigDirName + sys.Sep + ConfigFileName
	ConfigPathFlag      = "config"
	ConfigPathFlagShort = "c"
	ConfigPathFlagDesc  = "configuration file path (default is " + ConfigPathDefault + ")"
)
View Source
const (
	RaidConfigFileName = "raid.yaml"
)

Variables

View Source
var CfgPath string

Functions

func AddProfile

func AddProfile(profile Profile) error

AddProfile registers a profile in the config store.

func AddProfiles

func AddProfiles(profiles []Profile) error

AddProfiles registers multiple profiles in the config store.

func CloneRepository

func CloneRepository(repo Repo) error

CloneRepository clones a repository to its configured path. Skips if it already exists.

func ContainsEnv

func ContainsEnv(name string) bool

ContainsEnv reports whether an environment with the given name exists in the active profile.

func ContainsProfile

func ContainsProfile(name string) bool

ContainsProfile reports whether a profile with the given name is registered.

func CreateRepoConfigs

func CreateRepoConfigs(repos []RepoDraft)

CreateRepoConfigs writes a raid.yaml stub into each repository's local directory.

func ExecuteCommand

func ExecuteCommand(name string) error

ExecuteCommand runs the tasks for the named command, applying any output configuration.

func ExecuteEnv

func ExecuteEnv(name string) error

ExecuteEnv writes environment variables to each repo's .env file and runs the environment's tasks.

func ExecuteTask

func ExecuteTask(task Task) error

func ExecuteTasks

func ExecuteTasks(tasks []Task) error

func ForceLoad

func ForceLoad() error

ForceLoad rebuilds the context from the active profile, ignoring any cached state.

func GetEnv

func GetEnv() string

GetEnv returns the name of the currently active environment.

func InitConfig

func InitConfig() error

func Install

func Install(maxThreads int) error

Install clones all repositories in the active profile and runs install tasks.

func ListEnvs

func ListEnvs() []string

ListEnvs returns the names of all environments in the active profile.

func Load

func Load() error

Load initializes the context from the active profile, using cached results if available.

func LoadEnv

func LoadEnv() error

LoadEnv loads .env files from all repositories in the active profile into the process environment.

func RemoveProfile

func RemoveProfile(name string) error

RemoveProfile removes a registered profile by name.

func Set

func Set(key string, value any) error

Set stores key in the viper config and persists it to disk.

func SetEnv

func SetEnv(name string) error

SetEnv sets the named environment as the active environment.

func SetProfile

func SetProfile(name string) error

SetProfile sets the named profile as the active profile.

func ValidateProfile

func ValidateProfile(path string) error

ValidateProfile validates the profile file at path against the profile JSON schema.

func ValidateRepo

func ValidateRepo(path string) error

ValidateRepo validates the repo config file at path against the repo JSON schema.

func ValidateSchema

func ValidateSchema(path string, schemaPath string) error

ValidateSchema validates the file at path against the JSON schema at schemaPath. schemaPath must be an absolute or CWD-relative path to a schema file on disk.

func Write

func Write() error

Write persists the current viper config to disk.

func WriteProfileFile

func WriteProfileFile(draft ProfileDraft, path string) error

WriteProfileFile serializes draft as YAML and writes it to path, creating parent directories as needed.

Types

type Command

type Command struct {
	Name  string  `json:"name"`
	Usage string  `json:"usage"`
	Tasks []Task  `json:"tasks"`
	Out   *Output `json:"out,omitempty"`
}

Command is a named, user-defined CLI command that can be invoked via 'raid <name>'.

func GetCommands

func GetCommands() []Command

GetCommands returns all commands available in the active profile.

func (Command) IsZero

func (c Command) IsZero() bool

IsZero reports whether the command is uninitialized.

type Condition

type Condition struct {
	Platform string `json:"platform,omitempty"`
	Exists   string `json:"exists,omitempty"`
	Cmd      string `json:"cmd,omitempty"`
}

Condition guards a task — all specified fields must be satisfied for the task to run.

func (Condition) IsZero

func (c Condition) IsZero() bool

IsZero reports whether no condition fields are set.

type Context

type Context struct {
	Profile Profile
	Env     string
}

Context holds the active profile and environment for the current raid session.

type Env

type Env struct {
	Name      string   `json:"name"`
	Variables []EnvVar `json:"variables"`
	Tasks     []Task   `json:"tasks"`
}

Env represents a named environment with variables and tasks.

func (Env) IsZero

func (e Env) IsZero() bool

IsZero reports whether the environment is uninitialized.

type EnvVar

type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

EnvVar is a key/value pair written into a repository's .env file.

type Finding

type Finding struct {
	Severity   Severity
	Check      string
	Message    string
	Suggestion string // shown when non-empty
}

Finding represents the result of a single doctor check.

func RunDoctor

func RunDoctor() []Finding

RunDoctor performs all configuration checks and returns the findings.

type OnInstall

type OnInstall struct {
	Tasks []Task `json:"tasks"`
}

OnInstall holds the tasks to run during profile installation.

type Output

type Output struct {
	Stdout bool   `json:"stdout"`
	Stderr bool   `json:"stderr"`
	File   string `json:"file,omitempty"`
}

Output configures how a command's task output is handled. Stdout and Stderr default to true when Out is nil. When Out is set, only streams explicitly set to true are shown.

type Profile

type Profile struct {
	Name         string            `json:"name"`
	Path         string            `json:"path"`
	Repositories []Repo            `json:"repositories"`
	Environments []Env             `json:"environments"`
	Install      OnInstall         `json:"install"`
	Groups       map[string][]Task `json:"task_groups" yaml:"task_groups"`
	Commands     []Command         `json:"commands"`
}

Profile represents a named collection of repositories, environments, and task groups.

func ExtractProfile

func ExtractProfile(name, path string) (Profile, error)

ExtractProfile reads and returns a single named profile from the given file.

func ExtractProfiles

func ExtractProfiles(path string) ([]Profile, error)

ExtractProfiles reads all profiles from a YAML or JSON file.

func GetProfile

func GetProfile() Profile

GetProfile returns the currently active profile.

func ListProfiles

func ListProfiles() []Profile

ListProfiles returns all registered profiles.

func (Profile) IsZero

func (p Profile) IsZero() bool

IsZero reports whether the profile is uninitialized.

type ProfileDraft

type ProfileDraft struct {
	Name         string      `yaml:"name"`
	Repositories []RepoDraft `yaml:"repositories,omitempty"`
}

ProfileDraft is the minimal structure written to a new profile file.

type Repo

type Repo struct {
	Name         string    `json:"name"`
	Path         string    `json:"path"`
	URL          string    `json:"url"`
	Branch       string    `json:"branch"`
	Environments []Env     `json:"environments"`
	Install      OnInstall `json:"install"`
	Commands     []Command `json:"commands"`
}

Repo represents a single repository entry in a profile.

func ExtractRepo

func ExtractRepo(path string) (Repo, error)

ExtractRepo reads and parses the raid.yaml from the given repository directory.

func (Repo) IsZero

func (r Repo) IsZero() bool

IsZero reports whether the repo is uninitialized.

type RepoDraft

type RepoDraft struct {
	Name   string `yaml:"name"`
	Path   string `yaml:"path"`
	URL    string `yaml:"url"`
	Branch string `yaml:"branch,omitempty"`
}

RepoDraft holds the fields collected for each repository during profile creation.

func CollectRepos

func CollectRepos(reader *bufio.Reader) []RepoDraft

CollectRepos runs an interactive prompt loop to collect repository details from reader.

type Severity

type Severity int

Severity indicates the importance of a doctor finding.

const (
	SeverityOK Severity = iota
	SeverityWarn
	SeverityError
)

type Task

type Task struct {
	Type       TaskType   `json:"type"`
	Concurrent bool       `json:"concurrent,omitempty"`
	Condition  *Condition `json:"condition,omitempty"`
	// Shell
	Cmd     string `json:"cmd,omitempty"`
	Literal bool   `json:"literal,omitempty"`
	Shell   string `json:"shell,omitempty"`
	// Script
	Path   string `json:"path,omitempty"`
	Runner string `json:"runner,omitempty"`
	// HTTP
	URL  string `json:"url,omitempty"`
	Dest string `json:"dest,omitempty"`
	// Wait
	Timeout string `json:"timeout,omitempty"`
	// Template
	Src string `json:"src,omitempty"`
	// Group
	Ref      string `json:"ref,omitempty"`
	Parallel bool   `json:"parallel,omitempty"`
	// Git
	Op     string `json:"op,omitempty"`
	Branch string `json:"branch,omitempty"`
	// Prompt / Confirm / Print
	Message string `json:"message,omitempty"`
	// Prompt
	Var     string `json:"var,omitempty"`
	Default string `json:"default,omitempty"`
	// Print
	Color string `json:"color,omitempty"`
	// Retry
	Attempts int    `json:"attempts,omitempty"`
	Delay    string `json:"delay,omitempty"`
}

Task represents a single unit of work in a task sequence.

func (Task) Expand

func (t Task) Expand() Task

Expand returns a copy of the task with all string fields passed through environment variable expansion.

func (Task) IsZero

func (t Task) IsZero() bool

IsZero reports whether the task has no type set.

type TaskType

type TaskType string

TaskType identifies which task executor to dispatch to.

const (
	Shell    TaskType = "shell"
	Script   TaskType = "script"
	HTTP     TaskType = "http"
	Wait     TaskType = "wait"
	Template TaskType = "template"
	Group    TaskType = "group"
	Git      TaskType = "git"
	Prompt   TaskType = "prompt"
	Confirm  TaskType = "confirm"
	Print    TaskType = "print"
)

func (TaskType) ToLower

func (t TaskType) ToLower() TaskType

ToLower returns the task type normalized to lowercase for case-insensitive comparisons.

Jump to

Keyboard shortcuts

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