Documentation
¶
Index ¶
- Constants
- Variables
- func WithExecutionContext(ctx context.Context, execCtx ExecutionContext) context.Context
- type Choice
- type ClearCurrentCommand
- type CloneCommand
- type CommandSpec
- type ComposeFiles
- type DisableCommand
- type EnableCommand
- type EnvFile
- type ExecutionContext
- type ExecutionContextMiddleware
- type ExecutionTarget
- type Extension
- type ExtensionSpec
- type ExtensionType
- type ExtraComposeFile
- type Hook
- type HookEntry
- type HookPhase
- type HookRun
- type InitHookEntry
- type InitialiseCommand
- type InvalidPreferencesError
- type InvalidProjectConfigError
- type InvalidWorkspaceConfigError
- type LoaderCondition
- type LoaderPropertyCondition
- type LsQuery
- type Manager
- func (m *Manager) ClearCurrent(_ context.Context, cmd ClearCurrentCommand) error
- func (m *Manager) Clone(ctx context.Context, cmd CloneCommand) error
- func (m *Manager) Disable(ctx context.Context, cmd DisableCommand) error
- func (m *Manager) Enable(ctx context.Context, cmd EnableCommand) error
- func (m *Manager) Initialise(ctx context.Context, cmd InitialiseCommand) error
- func (m *Manager) Ls(_ context.Context, query LsQuery) error
- func (m *Manager) ProjectChoices(ctx context.Context, query ProjectChoicesQuery) ([]Choice, error)
- func (m *Manager) Projects(ctx context.Context, _ ProjectsQuery) error
- func (m *Manager) ShowCurrent(_ context.Context, query ShowCurrentQuery) error
- func (m *Manager) Switch(_ context.Context, cmd SwitchCommand) error
- func (m *Manager) WorkspaceChoices(_ context.Context, _ WorkspaceChoicesQuery) ([]Choice, error)
- type NetworkOverlayConfig
- type OverlayConfig
- type Project
- type ProjectChoicesQuery
- type ProjectConfig
- type ProjectFilter
- type ProjectMeta
- type ProjectRepositoryConfig
- type ProjectType
- type ProjectsQuery
- type Property
- type PulledInProject
- type Repository
- type Resolver
- type SetUpOpts
- type ShowCurrentQuery
- type SwitchCommand
- type SymlinkSpec
- type SyncFileSpec
- type UnconfiguredProject
- type UnconfiguredWorkspace
- type Workspace
- type WorkspaceChoicesQuery
- type WorkspaceMeta
Constants ¶
const DefaultPreferencesFileName = "orca.preferences.yaml"
const DefaultProjectFileName = "orca.project.yaml"
const DefaultWorkspaceFileName = "orca.workspace.yaml"
Variables ¶
var ( ErrInvalidExecutionContext = errors.New("invalid execution context") ErrCouldNotDetermineWorkspace = errors.New("could not determine workspace") ErrUnknownWorkspace = errors.New("unknown workspace") ErrUnknownProject = errors.New("unknown project") ErrInvalidInput = errors.New("invalid input") ErrFileNotFound = errors.New("file not found") ErrWorkspaceAlreadyExists = errors.New("workspace already exists") ErrDirectoryAlreadyExists = errors.New("directory already exists") ErrDirectoryDoesNotMatchOrigin = errors.New("directory does not contain a repo with the expected origin") ErrProjectConfigNotFound = errors.New("project config not found") ErrWorkspaceConfigNotFound = errors.New("workspace config not found") ErrConfigIsNotValidYAML = errors.New("config is not valid yaml") ErrUnknownExtension = errors.New("unknown extension") ErrUnknownHook = errors.New("unknown hook") ErrBranchNotFound = errors.New("branch not found") ErrLibraryProject = errors.New("library project") ErrCircularCloneOrder = errors.New("projects require, or are inside, each other in a circle") ErrEnclosingProjectNotCloned = errors.New("the project it's inside isn't cloned") )
var ( HookInitPost = Hook{"init", HookPhasePost} HookClonePost = Hook{"clone", HookPhasePost} HookUpPre = Hook{"up", HookPhasePre} HookUpPost = Hook{"up", HookPhasePost} HookDownPre = Hook{"down", HookPhasePre} HookDownPost = Hook{"down", HookPhasePost} )
var ErrNoExecutionContext = errors.New("no execution context was resolved for this message, it needs a target registering")
ErrNoExecutionContext means a handler needed an ExecutionContext, but its message has no target registered, so it was never resolved. This is a bug.
var ( // Every project's, the workspace repository's own included ProjectHooks = []Hook{HookClonePost, HookUpPre, HookUpPost, HookDownPre, HookDownPost} )
The hooks each config can define. There's no init.pre or clone.pre: a project's config can't be read until it's cloned, so nothing can run before.
Functions ¶
func WithExecutionContext ¶
func WithExecutionContext(ctx context.Context, execCtx ExecutionContext) context.Context
Types ¶
type Choice ¶ added in v0.20.0
type Choice struct {
Value string
// Shown alongside the value where the shell supports it, may be empty
Description string
}
Choice is a value the user can choose for an argument or flag, offered by shell completion.
type ClearCurrentCommand ¶
func (ClearCurrentCommand) MessageName ¶
func (ClearCurrentCommand) MessageName() string
type CloneCommand ¶
type CloneCommand struct {
bus.Returns[bus.Void]
WorkspaceName string
Project string
To string
// Clone without running the projects' clone.post hooks
SkipHooks bool
// Run every extension the hooks run without asking, and without recording
// them as trusted
Yes bool
}
func (CloneCommand) MessageName ¶
func (CloneCommand) MessageName() string
type CommandSpec ¶ added in v0.23.0
type CommandSpec struct {
Command string
Service string
DefaultArgs []string
// Relative to the directory the extension runs in
Chdir string
}
CommandSpec runs a command: in a compose service when Service is set, otherwise on the host.
func (CommandSpec) Type ¶ added in v0.23.0
func (CommandSpec) Type() ExtensionType
type ComposeFiles ¶
type ComposeFiles struct {
Primary string
Extras []ExtraComposeFile
}
type DisableCommand ¶ added in v0.21.0
type DisableCommand struct {
bus.Returns[bus.Void]
Workspace string
Projects []string
// Orphan leaves the projects running, instead of stopping them
Orphan bool
}
func (DisableCommand) MessageName ¶ added in v0.21.0
func (DisableCommand) MessageName() string
type EnableCommand ¶ added in v0.21.0
func (EnableCommand) MessageName ¶ added in v0.21.0
func (EnableCommand) MessageName() string
type ExecutionContext ¶
func ExecutionContextFrom ¶
func ExecutionContextFrom(ctx context.Context) (ExecutionContext, error)
ExecutionContextFrom returns the ExecutionContext resolved for the message being handled. It should only be called from handlers, whose message has a target registered with the ExecutionContextMiddleware.
func (ExecutionContext) Dir ¶
func (e ExecutionContext) Dir() string
Dir is the directory to run in: the project's, if there is one, otherwise the working directory.
type ExecutionContextMiddleware ¶
type ExecutionContextMiddleware struct {
// contains filtered or unexported fields
}
ExecutionContextMiddleware resolves the ExecutionContext for a message before it's handled, and passes it along in the context.Context, to be read with ExecutionContextFrom.
Only messages with a target registered (see Target) are resolved, others are passed through as they are.
func NewExecutionContextMiddleware ¶
func NewExecutionContextMiddleware(resolver resolver) *ExecutionContextMiddleware
func (*ExecutionContextMiddleware) Handle ¶
func (m *ExecutionContextMiddleware) Handle(ctx context.Context, msg bus.Named, next bus.Next) (any, error)
Handle is the bus.Middleware.
func (*ExecutionContextMiddleware) Target ¶
func (m *ExecutionContextMiddleware) Target[M bus.Named](fn func(msg M) ExecutionTarget)
Target registers how to get the target for messages of type M. Registering a second target for the same type is a programming error, so panics.
func (*ExecutionContextMiddleware) TargetedTypes ¶
func (m *ExecutionContextMiddleware) TargetedTypes() []string
TargetedTypes returns the type of every message that has a target, e.g. "controller.UpCommand".
type ExecutionTarget ¶
type ExecutionTarget struct {
Workspace string
Project string
// When the workspace can't be determined, carry on with only the working
// directory, instead of failing. Used by commands that are still useful
// outside of orca, like the git commands in any repository.
WorkspaceOptional bool
// The command only applies to projects with a compose stack, so fails for a
// library project, whether it's given or worked out from the directory.
ServicesOnly bool
}
ExecutionTarget is the workspace and project a message runs against, as given by the user. Either may be empty, in which case they're resolved as usual (see Resolver.Resolve).
type Extension ¶
type Extension struct {
Name string
// Shown next to the name when completing it
Description string
Spec ExtensionSpec
}
type ExtensionSpec ¶ added in v0.23.0
type ExtensionSpec interface {
Type() ExtensionType
// contains filtered or unexported methods
}
ExtensionSpec is what an extension does, one of CommandSpec, SyncFileSpec or SymlinkSpec. Code handling extensions switches on the concrete type, and panics on any other, as the set is closed: only this package's types implement it.
type ExtensionType ¶ added in v0.23.0
type ExtensionType string
ExtensionType is what kind of thing an extension does, and so which fields it takes.
const ( ExtensionTypeCommand ExtensionType = "command" ExtensionTypeSyncFile ExtensionType = "syncFile" ExtensionTypeSymlink ExtensionType = "symlink" )
type ExtraComposeFile ¶
type ExtraComposeFile struct {
Path string
When []LoaderCondition
}
type Hook ¶ added in v0.23.0
Hook is an operation and a phase, e.g. clone.post.
type HookEntry ¶ added in v0.23.0
type HookEntry struct {
Extension string
}
HookEntry is one of the project's own extensions that a hook runs.
type HookPhase ¶ added in v0.23.0
type HookPhase string
HookPhase is whether a hook runs before or after its operation.
type InitHookEntry ¶ added in v0.23.0
InitHookEntry is one extension the workspace's init.post runs. The workspace config has no extensions, so it's one of a project's, and runs in that project's directory.
type InitialiseCommand ¶
type InitialiseCommand struct {
bus.Returns[bus.Void]
// A github repository in the format 'owner/repo' to clone the workspace
// config from, takes precedence over SourceDirectory
SourceRepo string
// The branch of SourceRepo to read the workspace config from, and to
// clone. Empty means the repository's default branch.
Branch string
SourceDirectory string
WorkspaceFileName string
Into string
// Clone without running any hooks
SkipHooks bool
// Run every extension the hooks run without asking, and without recording
// them as trusted
Yes bool
}
func (InitialiseCommand) MessageName ¶
func (InitialiseCommand) MessageName() string
type InvalidPreferencesError ¶ added in v0.21.0
func (InvalidPreferencesError) Error ¶ added in v0.21.0
func (err InvalidPreferencesError) Error() string
type InvalidProjectConfigError ¶ added in v0.22.0
func (InvalidProjectConfigError) Error ¶ added in v0.22.0
func (err InvalidProjectConfigError) Error() string
type InvalidWorkspaceConfigError ¶
func (InvalidWorkspaceConfigError) Error ¶
func (err InvalidWorkspaceConfigError) Error() string
type LoaderCondition ¶
type LoaderCondition struct {
OS string
Arch string
Property LoaderPropertyCondition
}
type LoaderPropertyCondition ¶
type LsQuery ¶
func (LsQuery) MessageName ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) ClearCurrent ¶
func (m *Manager) ClearCurrent(_ context.Context, cmd ClearCurrentCommand) error
func (*Manager) Disable ¶ added in v0.21.0
func (m *Manager) Disable(ctx context.Context, cmd DisableCommand) error
func (*Manager) Enable ¶ added in v0.21.0
func (m *Manager) Enable(ctx context.Context, cmd EnableCommand) error
func (*Manager) Initialise ¶
func (m *Manager) Initialise(ctx context.Context, cmd InitialiseCommand) error
func (*Manager) ProjectChoices ¶ added in v0.20.0
func (*Manager) Projects ¶ added in v0.21.0
func (m *Manager) Projects(ctx context.Context, _ ProjectsQuery) error
Projects lists the workspace's projects, and whether each is enabled, cloned and running. When docker can't be asked, running is shown as '?', rather than failing.
func (*Manager) ShowCurrent ¶
func (m *Manager) ShowCurrent(_ context.Context, query ShowCurrentQuery) error
func (*Manager) WorkspaceChoices ¶ added in v0.20.0
type NetworkOverlayConfig ¶
type OverlayConfig ¶
type OverlayConfig struct {
Network NetworkOverlayConfig
}
type Project ¶
type Project struct {
Name string
Type ProjectType
RepositoryConfig ProjectRepositoryConfig
// Path is where the project is cloned, relative to the directory projects
// are cloned into. Empty means the project's name.
Path string
ProjectDir string
Requires []string
Config ProjectConfig
IsRegistered bool
// Disabled projects are left out of workspace-wide commands, unless an
// enabled project requires them. Set from the preferences file.
Disabled bool
}
func TrimRequires ¶ added in v0.21.0
TrimRequires returns copies of projects that only require each other, so a subset of a workspace's projects can be ordered on its own.
func (Project) DefinedHooks ¶ added in v0.23.0
DefinedHooks returns the project's hooks that run something.
func (Project) EnvFilePaths ¶
func (Project) FindExtension ¶
FindExtension returns the extension the project's config defines with the name.
func (Project) GetChildren ¶
func (Project) GetParents ¶
type ProjectChoicesQuery ¶ added in v0.20.0
type ProjectChoicesQuery struct {
bus.Returns[[]Choice]
Workspace string
Filter ProjectFilter
// Leaves out libraries, for commands that only apply to projects with a
// compose stack
ServicesOnly bool
}
ProjectChoicesQuery lists the projects in the workspace, which is worked out as it is for any command, from the working directory or Workspace.
func (ProjectChoicesQuery) MessageName ¶ added in v0.20.0
func (ProjectChoicesQuery) MessageName() string
type ProjectConfig ¶
type ProjectFilter ¶ added in v0.21.0
type ProjectFilter string
ProjectFilter narrows the projects offered by ProjectChoicesQuery.
const ( AllProjects ProjectFilter = "" EnabledProjects ProjectFilter = "enabled" DisabledProjects ProjectFilter = "disabled" )
type ProjectMeta ¶
type ProjectMeta struct {
Name string
Path string
WorkspaceName string
// Type is recorded when the project is registered, so it's known without
// loading the workspace config. Empty for projects registered before types
// existed, which are services.
Type ProjectType
}
type ProjectRepositoryConfig ¶
type ProjectType ¶ added in v0.22.0
type ProjectType string
ProjectType is what a project is for: running a compose stack, or only being cloned and set up.
const ( ProjectTypeService ProjectType = "service" ProjectTypeLibrary ProjectType = "library" )
type ProjectsQuery ¶ added in v0.21.0
func (ProjectsQuery) MessageName ¶ added in v0.21.0
func (ProjectsQuery) MessageName() string
type PulledInProject ¶ added in v0.21.0
PulledInProject is a disabled project that runs anyway, as RequiredBy requires it.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(fs afero.Fs, userConfig userConfig) *Repository
func (*Repository) LoadUnconfiguredWorkspace ¶
func (wcr *Repository) LoadUnconfiguredWorkspace(path string) (*UnconfiguredWorkspace, error)
func (*Repository) ParseUnconfiguredWorkspace ¶
func (wcr *Repository) ParseUnconfiguredWorkspace(contents []byte, path string) (*UnconfiguredWorkspace, error)
ParseUnconfiguredWorkspace loads a workspace from raw config contents, e.g. when fetched from a remote. The path is only used for reporting.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
func NewResolver ¶
func NewResolver(cfg configManager, workspaceRepo workspaceRepository) *Resolver
type SetUpOpts ¶ added in v0.23.0
type SetUpOpts struct {
// Each project's clone.post runs, in this order
Projects []string
// Then the workspace's init.post
Initialise bool
// Run every extension without asking, and without recording them as trusted
Yes bool
}
SetUpOpts are the hooks to run once projects are cloned.
type ShowCurrentQuery ¶
func (ShowCurrentQuery) MessageName ¶
func (ShowCurrentQuery) MessageName() string
type SwitchCommand ¶
func (SwitchCommand) MessageName ¶
func (SwitchCommand) MessageName() string
type SymlinkSpec ¶ added in v0.23.0
SymlinkSpec creates Target as a symlink to Source.
func (SymlinkSpec) Type ¶ added in v0.23.0
func (SymlinkSpec) Type() ExtensionType
type SyncFileSpec ¶ added in v0.23.0
SyncFileSpec creates Target from Source, when Target doesn't exist.
func (SyncFileSpec) Type ¶ added in v0.23.0
func (SyncFileSpec) Type() ExtensionType
type UnconfiguredProject ¶
type UnconfiguredProject struct {
Name string
Type ProjectType
RepositoryConfig ProjectRepositoryConfig
Path string
}
type UnconfiguredWorkspace ¶
type UnconfiguredWorkspace struct {
Name string
ConfigPath string
PreferencesPath string
Projects []UnconfiguredProject
}
type Workspace ¶
type Workspace struct {
Name string
ConfigPath string
Projects []Project
OverlayConfig OverlayConfig `yaml:"overlays"`
// PreferencesPath is the developer's preferences file, which may not exist
PreferencesPath string
// UnknownPreferenceProjects are listed in the preferences file, but aren't
// in the workspace, so are ignored
UnknownPreferenceProjects []string
// The workspace's init.post, which runs projects' extensions once every
// project is cloned and set up
InitHooks []InitHookEntry
}
func (*Workspace) EnabledProjects ¶ added in v0.21.0
EnabledProjects returns the projects that aren't disabled, in the order they're configured.
func (*Workspace) GetUniqueHosts ¶
func (*Workspace) GetUniqueTLSCertificates ¶
func (*Workspace) RunSet ¶ added in v0.21.0
func (ws *Workspace) RunSet() ([]Project, []PulledInProject)
RunSet returns the projects that workspace-wide commands run: the enabled ones, and every project they require, directly or not, even if it's disabled. The disabled projects that were pulled in are returned too, so they can be warned about. Libraries are never run, so they're left out, and requirements on them are kept, to be trimmed or checked by the caller.
type WorkspaceChoicesQuery ¶ added in v0.20.0
WorkspaceChoicesQuery lists the registered workspaces.
func (WorkspaceChoicesQuery) MessageName ¶ added in v0.20.0
func (WorkspaceChoicesQuery) MessageName() string
type WorkspaceMeta ¶
type WorkspaceMeta struct {
Name string
Path string
Projects []ProjectMeta
}