repository

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TasksSaveFile holds the absolute path to the tasks.json file in the user's config directory.
	TasksSaveFile string
)
View Source
var (
	// WorkspacesSaveFile holds the absolute path to the workspaces.json file in the user's config directory.
	WorkspacesSaveFile string
)

Functions

func DeleteTask

func DeleteTask(name string) error

DeleteTask removes a task from the local configuration file by name.

func DeleteWorkspace

func DeleteWorkspace(name string) error

DeleteWorkspace removes a workspace from the local configuration file by name.

func FindTaskByName

func FindTaskByName(name string) (*models.Task, error)

FindTaskByName retrieves a task by its name from the saved tasks.

func FindWorkspaceByName

func FindWorkspaceByName(name string) (*models.Workspace, error)

FindWorkspaceByName retrieves a workspace by its name from the saved workspaces.

func ImportTasks

func ImportTasks(tasks []models.Task) error

ImportTasks validates the whole batch (VAL-001, VAL-003, VAL-004, VAL-005) and writes all entries only if every entry is valid. On failure it returns an aggregate error and writes nothing.

func ImportWorkspaces

func ImportWorkspaces(workspaces []models.Workspace) error

ImportWorkspaces mirrors ImportTasks for workspaces (VAL-002, VAL-004, VAL-005).

func OpenSource

func OpenSource(source string) (io.ReadCloser, error)

OpenSource returns a reader for the given --from-json value: os.Stdin when source == "-", otherwise the opened file. The returned ReadCloser is always safe to Close.

func ReadJSONSource

func ReadJSONSource[T any](source string) (T, error)

ReadJSONSource opens source via OpenSource, reads all bytes, and unmarshals them into T. It consolidates the open-read-unmarshal sequence shared by all --from-json command handlers.

func ReadTasks

func ReadTasks() ([]models.Task, error)

ReadTasks loads all tasks from the persistence file.

func ReadWorkspaces

func ReadWorkspaces() ([]models.Workspace, error)

ReadWorkspaces loads all workspaces from the persistence file.

func SaveTask

func SaveTask(task models.Task) error

SaveTask saves a task to the local configuration file.

func SaveWorkspace

func SaveWorkspace(workspace models.Workspace) error

SaveWorkspace saves a workspace to the local configuration file.

func UpdateTask

func UpdateTask(originalName string, updatedTask models.Task) error

UpdateTask modifies an existing task in the local configuration file.

func UpdateWorkspace

func UpdateWorkspace(originalName string, updatedWorkspace models.Workspace) error

UpdateWorkspace replaces the workspace stored under originalName with updatedWorkspace. The replacement is a single atomic write, so a rename never leaves the file with a duplicate or a missing record.

func ValidateTaskBatch

func ValidateTaskBatch(tasks []models.Task) error

ValidateTaskBatch checks the batch for all problems (VAL-001, VAL-003, VAL-004, VAL-005) without modifying any file. Returns nil when all entries are valid.

func ValidateWorkspaceBatch

func ValidateWorkspaceBatch(workspaces []models.Workspace) error

ValidateWorkspaceBatch checks the batch (VAL-002, VAL-004, VAL-005) without modifying any file.

Types

type JSONRepository

type JSONRepository[T NamedEntity] struct {
	// contains filtered or unexported fields
}

JSONRepository persists a slice of T as a single JSON object file whose only top-level key is jsonKey, e.g. {"tasks": [...]}. The append rule is injected via onAppend (Strategy) so each repository can choose its own policy; both current repositories use the shared rejectDuplicateName strategy.

The save-file path is resolved lazily through getSaveFile rather than captured at construction time, so callers (notably tests) that reassign the package path variable after init() are honored on the next operation.

func NewTaskRepository

func NewTaskRepository(getSaveFile func() string) *JSONRepository[models.Task]

NewTaskRepository builds the task repository: tasks are keyed under "tasks" and rejected on a case-sensitive name collision, since the task name is the handle every read path (find, run, completion, workspace selector) keys on.

func NewWorkspaceRepository

func NewWorkspaceRepository(getSaveFile func() string) *JSONRepository[models.Workspace]

NewWorkspaceRepository builds the workspace repository: workspaces are keyed under "workspaces" and rejected on a case-sensitive name collision.

func (*JSONRepository[T]) Delete

func (r *JSONRepository[T]) Delete(name string) error

Delete removes the item whose name equals name, matching case-sensitively. Deleting a non-existent name succeeds silently, preserving prior behavior.

func (*JSONRepository[T]) FindByName

func (r *JSONRepository[T]) FindByName(name string) (*T, error)

FindByName retrieves the item whose name matches name. The comparison is case-sensitive, matching the uniqueness rule enforced by onAppend on write, so a lookup never resolves a name the repository would treat as distinct.

func (*JSONRepository[T]) ReadAll

func (r *JSONRepository[T]) ReadAll() ([]T, error)

ReadAll loads every persisted item, creating the backing file on first use. An empty file yields (nil, nil); malformed JSON returns the unmarshal error.

func (*JSONRepository[T]) Save

func (r *JSONRepository[T]) Save(item T) error

Save appends item according to the injected onAppend strategy and persists the result. The strategy decides whether a duplicate name is allowed.

func (*JSONRepository[T]) Update

func (r *JSONRepository[T]) Update(originalName string, updated T) error

Update replaces the item stored under originalName with updated, matching the original name case-sensitively. It returns an error when no such item exists.

func (*JSONRepository[T]) WriteAll

func (r *JSONRepository[T]) WriteAll(items []T) error

WriteAll atomically replaces the whole file with items, serialized as {jsonKey: items}. It writes to a temporary file in the same directory and renames it over the destination: os.Rename is atomic within a filesystem, so a crash mid-write can never leave a truncated or corrupt JSON file behind.

type NamedEntity

type NamedEntity interface {
	GetName() string
}

NamedEntity is the constraint for items persisted by JSONRepository: any type that exposes its unique name. It is defined here, where it is consumed, per the project's Go interface guideline.

Jump to

Keyboard shortcuts

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