adapters

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package adapters provides adapter interfaces and lightweight types used by the TUI to decouple it from the internal domain packages.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is used when a requested item cannot be found in the repository.

Functions

This section is empty.

Types

type CommandSetSummary

type CommandSetSummary struct {
	Name        string
	Description string
	Version     string
	Commands    []string
	AuthorName  string
	AuthorEmail string
	Tags        []string
	CreatedAt   string
	LastRun     string
}

CommandSetSummary represents a lightweight summary of a command set used by the TUI.

type ExecutorAdapter

type ExecutorAdapter interface {
	Run(ctx context.Context, name string, commands []string) (RunHandle, error)
}

ExecutorAdapter describes running and streaming commandset executions. The `commands` slice is the list of shell commands to execute sequentially.

func NewExecutorAdapter

func NewExecutorAdapter(r executor.Runner) ExecutorAdapter

NewExecutorAdapter constructs an ExecutorAdapter backed by the provided Runner.

type ImportExportAdapter

type ImportExportAdapter interface {
	Export(ctx context.Context, name string, dest string) error
	// ImportSet imports a command set file into the active DB. `policy` is one of
	// rename|skip|overwrite|merge and `dedupe` applies when merging.
	ImportSet(ctx context.Context, src string, policy string, dedupe bool) error
	// ImportDB imports an entire database file as the active DB; `overwrite`
	// indicates whether to replace the destination if it exists.
	ImportDB(ctx context.Context, src string, overwrite bool) error
}

ImportExportAdapter describes import/export operations.

type ImportExportAdapterImpl

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

ImportExportAdapterImpl adapts exporter/importer package functions to the UI adapter. ImportExportAdapterImpl adapts exporter/importer package functions to the UI adapter.

func NewImportExportAdapter

func NewImportExportAdapter(db *sql.DB) *ImportExportAdapterImpl

NewImportExportAdapter constructs a new ImportExportAdapter backed by db.

func (*ImportExportAdapterImpl) Export

func (i *ImportExportAdapterImpl) Export(_ context.Context, name string, dest string) error

Export exports either a single command set (when name is non-empty) or the entire database to dest.

func (*ImportExportAdapterImpl) ImportDB

func (i *ImportExportAdapterImpl) ImportDB(_ context.Context, src string, overwrite bool) error

ImportDB imports a database file into the active DB, overwriting if requested.

func (*ImportExportAdapterImpl) ImportSet

func (i *ImportExportAdapterImpl) ImportSet(_ context.Context, src string, policy string, dedupe bool) error

ImportSet imports a command set file from src using the given policy and dedupe options.

type InstallerAdapter

type InstallerAdapter interface {
	Install(ctx context.Context, opts install.Options) ([]string, error)
	Uninstall(ctx context.Context) ([]string, error)
}

InstallerAdapter minimal interface for install/uninstall Install accepts options controlling system/user scope and add-to-path behavior. Uninstall returns the human-readable actions performed.

type InstallerAdapterImpl

type InstallerAdapterImpl struct{}

InstallerAdapterImpl delegates install/uninstall operations to internal/install.

func NewInstallerAdapter

func NewInstallerAdapter() *InstallerAdapterImpl

NewInstallerAdapter returns a new InstallerAdapterImpl.

func (*InstallerAdapterImpl) Install

func (i *InstallerAdapterImpl) Install(_ context.Context, opts install.Options) ([]string, error)

Install executes the install with given options and returns performed actions.

func (*InstallerAdapterImpl) Uninstall

func (i *InstallerAdapterImpl) Uninstall(_ context.Context) ([]string, error)

Uninstall performs uninstall and returns the performed actions.

type RegistryAdapter

type RegistryAdapter interface {
	ListCommandSets(ctx context.Context) ([]CommandSetSummary, error)
	GetCommandSet(ctx context.Context, name string) (CommandSetSummary, error)
	GetCommands(ctx context.Context, name string) ([]string, error)
	SaveCommandSet(ctx context.Context, cs CommandSetSummary) error
	DeleteCommandSet(ctx context.Context, name string) error
	// ReplaceCommands replaces the commands for an existing command set.
	ReplaceCommands(ctx context.Context, name string, commands []string) error
	// UpdateCommandSet updates metadata and tags for an existing command set.
	UpdateCommandSet(ctx context.Context, oldName string, cs CommandSetSummary) error
	// UpdateCommandSetAndReplaceCommands performs an atomic metadata+commands update
	// and records a single 'update' version representing the final state.
	UpdateCommandSetAndReplaceCommands(ctx context.Context, oldName string, cs CommandSetSummary) error
	// ListVersionsByName returns the versions for a command set (newest first)
	ListVersionsByName(ctx context.Context, name string) ([]Version, error)
	// ApplyVersionByName applies the specified historic version to the named command set (rollback)
	ApplyVersionByName(ctx context.Context, name string, versionNum int) error
	// DeleteVersionByName deletes a specific version record for the named command set
	DeleteVersionByName(ctx context.Context, name string, versionNum int) error
}

RegistryAdapter describes the minimal subset of registry operations used by the UI. Keep methods small and easy to mock for tests.

type RegistryAdapterImpl

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

RegistryAdapterImpl adapts internal/registry.Repository to the UI adapters.RegistryAdapter interface.

func NewRegistryAdapter

func NewRegistryAdapter(repo *registry.Repository) *RegistryAdapterImpl

NewRegistryAdapter returns an adapter that wraps an internal registry.Repository.

func (*RegistryAdapterImpl) ApplyVersionByName

func (r *RegistryAdapterImpl) ApplyVersionByName(_ context.Context, name string, versionNum int) error

ApplyVersionByName applies a historical version to the named set (rollback).

func (*RegistryAdapterImpl) Close

func (r *RegistryAdapterImpl) Close() error

Close closes the underlying repository database connection if present.

func (*RegistryAdapterImpl) DeleteCommandSet

func (r *RegistryAdapterImpl) DeleteCommandSet(_ context.Context, name string) error

DeleteCommandSet deletes a command set by name.

func (*RegistryAdapterImpl) DeleteVersionByName added in v1.2.5

func (r *RegistryAdapterImpl) DeleteVersionByName(_ context.Context, name string, versionNum int) error

DeleteVersionByName deletes a specific version for the named command set.

func (*RegistryAdapterImpl) GetCommandSet

func (r *RegistryAdapterImpl) GetCommandSet(_ context.Context, name string) (CommandSetSummary, error)

GetCommandSet retrieves a full CommandSetSummary by name.

func (*RegistryAdapterImpl) GetCommands

func (r *RegistryAdapterImpl) GetCommands(_ context.Context, name string) ([]string, error)

GetCommands returns only the commands for a named command set.

func (*RegistryAdapterImpl) ListCommandSets

func (r *RegistryAdapterImpl) ListCommandSets(_ context.Context) ([]CommandSetSummary, error)

ListCommandSets returns a list of command set summaries.

func (*RegistryAdapterImpl) ListVersionsByName

func (r *RegistryAdapterImpl) ListVersionsByName(_ context.Context, name string) ([]Version, error)

ListVersionsByName lists historical versions for the named command set.

func (*RegistryAdapterImpl) ReplaceCommands

func (r *RegistryAdapterImpl) ReplaceCommands(_ context.Context, name string, commands []string) error

ReplaceCommands replaces the commands for the named set.

func (*RegistryAdapterImpl) SaveCommandSet

func (r *RegistryAdapterImpl) SaveCommandSet(_ context.Context, cs CommandSetSummary) error

SaveCommandSet creates a new command set in the underlying repository.

func (*RegistryAdapterImpl) UpdateCommandSet

func (r *RegistryAdapterImpl) UpdateCommandSet(_ context.Context, oldName string, cs CommandSetSummary) error

UpdateCommandSet updates metadata and tags for an existing set.

func (*RegistryAdapterImpl) UpdateCommandSetAndReplaceCommands

func (r *RegistryAdapterImpl) UpdateCommandSetAndReplaceCommands(_ context.Context, oldName string, cs CommandSetSummary) error

UpdateCommandSetAndReplaceCommands performs an atomic metadata+commands update and records a single 'update' version representing the final state.

type RunEvent

type RunEvent struct {
	Line string
	Err  error
}

RunEvent represents streaming output from a running commandset.

type RunHandle

type RunHandle interface {
	// Events returns a receive-only channel for streaming output.
	Events() <-chan RunEvent
	// Cancel requests termination of the running command.
	Cancel()
	// WriteInput writes raw bytes into the running command's stdin. Returns
	// the number of bytes written or an error if the run does not accept input.
	WriteInput(p []byte) (int, error)
}

RunHandle is returned by ExecutorAdapter.Run to manage streaming output and cancellation.

type Version

type Version struct {
	Version     int
	CreatedAt   string
	AuthorName  string
	AuthorEmail string
	Description string
	Commands    []string
	Operation   string
}

Version mirrors registry.Version and is used by the TUI to render history entries.

Jump to

Keyboard shortcuts

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